{"id":13828471,"url":"https://github.com/n1crack/datatables","last_synced_at":"2025-05-16T05:05:03.912Z","repository":{"id":25963851,"uuid":"29405754","full_name":"n1crack/datatables","owner":"n1crack","description":"Simplify your Datatables server-side processing effortlessly using our lightning-fast PHP library, streamlining your workflow seamlessly.","archived":false,"fork":false,"pushed_at":"2024-06-24T21:10:25.000Z","size":244,"stargazers_count":267,"open_issues_count":6,"forks_count":90,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-04-08T15:04:29.750Z","etag":null,"topics":["codeigniter","datatables","datatables-library","datatables-serverside","laravel","mysql","php","php-library","prestashop","sqlite"],"latest_commit_sha":null,"homepage":"https://datatables.ozdemir.be/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/n1crack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"n1crack","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2015-01-17T21:09:10.000Z","updated_at":"2025-03-30T00:41:38.000Z","dependencies_parsed_at":"2024-08-04T09:08:41.839Z","dependency_job_id":"93fad2fc-adef-4ee8-a9a6-5d1c735125bd","html_url":"https://github.com/n1crack/datatables","commit_stats":{"total_commits":166,"total_committers":11,"mean_commits":"15.090909090909092","dds":"0.12048192771084343","last_synced_commit":"f5b5c327df8525d5ff949c6c90a7752c6071df2b"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n1crack%2Fdatatables","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n1crack%2Fdatatables/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n1crack%2Fdatatables/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n1crack%2Fdatatables/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/n1crack","download_url":"https://codeload.github.com/n1crack/datatables/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254471061,"owners_count":22076585,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codeigniter","datatables","datatables-library","datatables-serverside","laravel","mysql","php","php-library","prestashop","sqlite"],"created_at":"2024-08-04T09:02:48.316Z","updated_at":"2025-05-16T05:05:03.892Z","avatar_url":"https://github.com/n1crack.png","language":"PHP","funding_links":["https://github.com/sponsors/n1crack"],"categories":["PHP","Tools"],"sub_categories":[],"readme":"# Datatables library for PHP \n[![Latest Stable Version](https://poser.pugx.org/ozdemir/datatables/v/stable)](https://packagist.org/packages/ozdemir/datatables) [![PHP Composer](https://github.com/n1crack/datatables/actions/workflows/tests.yml/badge.svg)](https://github.com/n1crack/datatables/actions/workflows/tests.yml) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/n1crack/datatables/blob/master/LICENCE) \n\nSimplify your Datatables server-side processing effortlessly using our lightning-fast PHP library, streamlining your workflow seamlessly. [Live Demo](https://datatables.ozdemir.be/)\n\n## Features  \n* Easy to use. Generates json using only a few lines of code.\n* Editable columns with a closure function.\n* Supports custom filters.\n* Can handle most complicated queries.\n* Supports mysql and sqlite for native php.\n* Works with :\n    - [Laravel](https://datatables.ozdemir.be/laravel)\n    - [CodeIgniter 3](https://datatables.ozdemir.be/codeigniter)\n    - [CodeIgniter 4](https://datatables.ozdemir.be/codeigniter4)\n    - [Phalcon 3+](https://datatables.ozdemir.be/phalcon)\n    - [Prestashop](https://datatables.ozdemir.be/prestashop)\n    - [PostgreSql](https://datatables.ozdemir.be/postgresql)\n\n## Installation\n\n\u003e **NOTE:** version 2.0+ requires php 7.1.3+ ([php supported versions](http://php.net/supported-versions.php))\n\nThe recommended way to install the library is with [Composer](https://getcomposer.org/)\n\nIf you haven't started using composer, I highly recommend you to use it.\n\nPut a file named `composer.json` at the root of your project, containing this information: \n\n    {\n        \"require\": {\n           \"ozdemir/datatables\": \"2.*\"\n        }\n    }\n\nAnd then run: \n\n```\ncomposer install\n```\n\nOr just run : \n\n```\ncomposer require ozdemir/datatables\n```\n\nAdd the autoloader to your project:\n\n```php\n    \u003c?php\n\n    require_once 'vendor/autoload.php';\n```\n\nYou're now ready to begin using the Datatables php library.\n\n```php\n    \u003c?php\n    require_once 'vendor/autoload.php';\n\n    use Ozdemir\\Datatables\\Datatables;\n    use Ozdemir\\Datatables\\DB\\MySQL;\n\n    $config = [ 'host'     =\u003e 'localhost',\n                'port'     =\u003e '3306',\n                'username' =\u003e 'homestead',\n                'password' =\u003e 'secret',\n                'database' =\u003e 'sakila' ];\n\n    $dt = new Datatables( new MySQL($config) );\n\n    $dt-\u003equery('Select film_id, title, description from film');\n\n    echo $dt-\u003egenerate();\n```\nIf you are using a php framework such as codeigniter or laravel, you can use the relevant database adapter.\n\n```php\n// Codeigniter 4 Example\n\n\u003c?php\n\nnamespace App\\Controllers;\n\nuse Config\\Database;\nuse Ozdemir\\Datatables\\Datatables;\nuse Ozdemir\\Datatables\\DB\\Codeigniter4Adapter;\n\nclass Home extends BaseController\n{\n    public function index()\n    {\n        return view('index');\n    }\n\n    public function ajax()\n    {\n        // CI 4 builder class\n        $db = Database::connect();\n\n        $builder = $db-\u003etable('Track');\n        $builder-\u003eselect('TrackId, Name, UnitPrice');\n\n        // Datatables Php Library\n        $datatables = new Datatables(new Codeigniter4Adapter);\n\n        // using CI4 Builder\n        $datatables-\u003equery($builder);\n\n        // alternatively plain sql\n        // $datatables-\u003equery('Select TrackId, Name, UnitPrice from Track');\n\n        return $this-\u003eresponse-\u003esetJSON($datatables-\u003egenerate()-\u003etoJson());\n    }\n}\n```\n\n```php\n// Laravel Example\n\n\u003c?php\n// routes/web.php \n\nuse Ozdemir\\Datatables\\Datatables;\nuse Ozdemir\\Datatables\\DB\\LaravelAdapter;\n\nRoute::get('/ajax/laravel', function () {\n\n    $dt = new Datatables(new LaravelAdapter);\n\n    $dt-\u003equery(\n      Track::query()\n          -\u003eselect([\n              'TrackId',\n              'Track.Name',\n              'Title as Album',\n              'MediaType.Name as MediaType',\n              'UnitPrice',\n              'Milliseconds',\n              'Bytes',\n          ])\n          -\u003ejoin('Album', 'Album.AlbumId', 'Track.AlbumId')\n          -\u003ejoin('MediaType', 'MediaType.MediaTypeId', 'Track.MediaTypeId')\n    ); // same as the previous example, sql statement can be used.\n\n    return $dt-\u003egenerate();\n});\n\n```\n\n## Methods\nThis is the list of available public methods.\n\n__query($query)__ *required*\n\n* sets the sql query\n\n__generate()__  *required*\n\n* runs the queries and build outputs\n* returns the output as json\n* same as generate()-\u003etoJson()\n\n__toJson()__\n\n* returns the output as json\n* should be called after generate()\n\n__toArray()__\n\n* returns the output as array\n* should be called after generate()\n\n__add($column, function( $row ){})__\n\n* adds extra columns for custom usage\n\n__edit($column, function($row){})__\n\n* allows column editing\n\n__filter($column, function(){})__\n\n* allows custom filtering\n* it has the methods below\n    - escape($value)\n    - searchValue()\n    - defaultFilter()\n    - between($low, $high)\n    - whereIn($array)\n    - greaterThan($value)\n    - lessThan($value)\n\n__hide($columns)__\n\n* removes the column from output\n* It is useful when you only need to use the data in add() or edit() methods.\n\n__setDistinctResponseFrom($column)__\n\n* executes the query with the given column name and adds the returned data to the output with the distinctData key.\n\n__setDistinctResponse($output)__\n\n* adds the given data to the output with the distinctData key.\n\n__getColumns()__\n\n* returns column names (for dev purpose)\n\n__getQuery()__\n\n* returns the sql query string that is created by the library (for dev purpose)\n\n\n## Example\n\n```php\n    \u003c?php\n    require_once 'vendor/autoload.php';\n\n    use Ozdemir\\Datatables\\Datatables;\n    use Ozdemir\\Datatables\\DB\\SQLite;\n\n    $path = __DIR__ . '/../path/to/database.db';\n    $dt = new Datatables( new SQLite($path) );\n\n    $dt-\u003equery('Select id, name, email, age, address, plevel from users');\n\n    $dt-\u003eedit('id', function($data){\n        // return a link.\n        return \"\u003ca href='user.php?id=\" . $data['id'] . \"'\u003eedit\u003c/a\u003e\";\n    });\n\n    $dt-\u003eedit('email', function($data){\n        // masks email : mail@mail.com =\u003e m***@mail.com\n        return preg_replace('/(?\u003c=.).(?=.*@)/u','*', $data['email']);\n    });\n\n    $dt-\u003eedit('address', function($data){\n        // checks user access.\n        $current_user_plevel = 4;\n        if ($current_user_plevel \u003e 2 \u0026\u0026 $current_user_plevel \u003e $data['plevel']) {\n            return $data['address'];\n        }\n\n        return 'you are not authorized to view this column';\n    });\n    \n    $dt-\u003ehide('plevel'); // hides 'plevel' column from the output\n\n    $dt-\u003eadd('action', function($data){\n        // returns a link in a new column\n        return \"\u003ca href='user.php?id=\" . $data['id'] . \"'\u003eedit\u003c/a\u003e\";\n    });\n\n    $dt-\u003efilter('age', function (){\n        // applies custom filtering.\n        return $this-\u003ebetween(15, 30);\n    });\n\n    echo $dt-\u003egenerate()-\u003etoJson(); // same as 'echo $dt-\u003egenerate()';\n```\n\n## Road Map\n* better test suites for each class\n* improve integrations for php frameworks\n\n## Requirements\nComposer  \nDataTables \u003e 1.10  \nPHP \u003e 7.1.3\n\n## License\nCopyright (c) 2015 Yusuf ÖZDEMİR, released under [the MIT license](https://github.com/n1crack/Datatables/blob/master/LICENCE)\n\n#### If you like the library please consider giving a star. \n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fn1crack%2Fdatatables","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fn1crack%2Fdatatables","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fn1crack%2Fdatatables/lists"}