Code Monkey home page Code Monkey logo

datatables's Introduction

Datatables library for PHP

This is a php library that handles server-side processing for DataTables which is plug-in for the jQuery Javascript library.

Features

  1. Easy to use. Generates json using only a few lines of code.
  2. Editable columns with a closure function. (new)
  3. Auto detects HTTP method (POST or GET)
  4. Supports mysql and sqlite for native php.
  5. Works with laravel and codeigniter3. (new)

How to install?

Installation via composer is supported. Composer.

You don't have to install the composer to use the library. There is an example in the folder named 'nocomposer', but I highly recommend you to use composer.

Put a file named composer.json at the root of your project, containing this information:

{
    "require": {
       "ozdemir/datatables": "~1.*"
    }
}

And then run: composer install

Or just run : composer require ozdemir/datatables

Add the autoloader to your project:

    <?php

    require_once 'vendor/autoload.php'

You're now ready to begin using the Datatables php library.

How to use?

A simple ajax example:

    <?php
    require_once 'vendor/autoload.php';

    use Ozdemir\Datatables\Datatables;
    use Ozdemir\Datatables\DB\MySQL;

    $config = [ 'host'     => 'localhost',
                'post'     => '3306',
                'username' => 'homestead',
                'password' => 'secret',
                'database' => 'sakila' ];

    $dt = new Datatables( new MySQL($config) );

    $dt->query("Select film_id, title, description from film");

    echo $dt->generate();

There are several examples in the examples folder.

Methods

This is the list of available public methods.

  • query ( $query : string ) (required)
  • edit ($column:string, Closure:object ) (optional)
  • generate ( ) (required)

An example of methods

    <?php
    $dt = new Datatables( new MySQL($config) );

    $dt->query("Select id, name, email, address, plevel from users");

    $dt->edit('id', function($data){
        // return an edit link.
        return "<a href='user.php?id=" . $data['id'] . "'>edit</a>";
    });

    $dt->edit('email', function($data){
        // return [email protected] to m***@mail.com
        return preg_replace('/(?<=.).(?=.*@)/u','*', $data['email']);
    });

    $dt->edit('address', function($data){
        // check if user has authorized to see that
        $current_user_plevel = 4;
        if ($current_user_plevel > 2 && $current_user_plevel > $data['plevel']) {
            return $data['address'];
        }

        return 'you are not authorized to view this column';
    });

    echo $dt->generate();

Requirements

DataTables > 1.10
PHP > 5.3.7

License

Copyright (c) 2015 Yusuf ÖZDEMİR, released under the MIT license

datatables's People

Contributors

n1crack avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.