Provides server-side interoperability between CakePHP 2.x and jQuery DataTables plugin.
- Takes paginated data and converts into json response compatible with datatables
- Accepts dataTables ORDER BY requests
- Accepts dataTables WHERE conditions
- Accepts dataTables pagination
- Works with LinkableBehavior and to a lesser extent Containable
- PHP 5.x
- CakePHP 2.x
- LinkableBehavior is recommended but not required
You can either clone the project, download the project, or just copy & paste DataTableComponent.php into your projects Controller/Component directory
You can setup the demo locally with the following steps:
- Download demo application and move it into your webroot.
- Configure hosts and sites-enabled in apache to point at the location of demo application and setup the local hostname (ie datatables.local)
- Create a database (call this datatables)
- Configure database.php
- From the shell run Console/cake schema create
- Import app/Config/Schema/schema.sql into your database
- Ensure your app/tmp directory and app/tmp sub directories are writable
The demo application is designed for CakePHP 2.3 and was built on Ubuntu 12.10 running Apache2 with PHP 5.4. It does not have the full Cake framework in it, so you'll need to have cakephp in your php include paths or create a symbolic link to cake in test.
I'm in the process of enhancing documentation and moving it out of the README and into the wiki.
- Release Notes and Updates
- Getting Started
- Basic Usage
- Model Associations with Linkable
- Model Associations with Containable
- SUM, CONCAT, and other SQL Functions
Ordering and conditions supplied via DataTables work "automagically" and nothing else is needed. Deep relations using the ContainableBehavior will break the response due to the way conditions work within that behavior. To get around this it is recommended that the LinkableBehavior be used instead. The Component respects many of the options you can define within jQuery DataTables settings such as bSearchable and bSortable on a per field basis.
$this->paginate = array( 'fields' => array('Field.A','Field.B', 'Field.C','AssocatiatedModal.D'), 'conditions' => array( 'active'=>1 ) 'contain' => array('AssocatiatedModal') ); $this->set('response', $this->DataTable->getResponse()); $this->set('_serialize','response');
Using models from other controllers. Sometimes the case may be that you are in a CustomersController and you have a method within that wants to display data from another model such as an Order model. This can be accomplished with the following parameters:
Code is licensed under the MIT License.