PHP Interface for jQuery Datatables (http://datatables.net). Simple standalone, non-framework based.
This document assumes you have a working datatables frontend. Just point it to the usage code below.
This is the standard usage which builds and executes queries on the provided Db object.
$obj = DataTables::_get()
->setDB(Db::_get()) //add our database object
->setDataModel('\BrowserModel') //set datamodel to use for row formatting
->setColumns(array('engine','browser','platform','version','grade')) //set column defs
->setPrimary('id') //set primary column
->setTable('table') //set sql table to use
->setupFromRequest() //setup the object from $_REQUEST
->process(); //process the request
echo $obj; //uses __toString to output json
exit;
This is the alternative syntax where a Data Callback function is defined
$obj = DataTables::_get()
->setDataCallback('my_data_function')
->setDataModel('\BrowserModel') //set datamodel to use for row formatting
->setColumns(array('engine','browser','platform','version','grade')) //set column defs
->setupFromRequest() //setup the object from $_REQUEST
->process(); //process the request
echo $obj;
exit;
class BrowserModel extends \LSS\DataModel {
//format version
public function getVersion(){
return empty($this->version) ? '-' : $this->version;
}
}
Returns a new object same as
$obj = new DataTables();
Set the LSS\Db object to call queries on
Set the array of columns in the table (should match SQL names)
Set the primary column name (can be an array for multiple columns)
Set the database table to use (can be multiple just separate with commas) NOTE: currently does not support joins
Set the data callback function to provide data rather than direct DB querying The proper return is a 3-part array consisting of
function my_callback_function($columns,$where,$order_by,$limit,$arg1,$arg2){
//execute query here
return array($results,$count_results,$count_total);
}
Set the datamodel class to use. By Default uses \LSS\DataModel with no extensions
Store arbitrary params for use in resulting JSON
Returns the number of columns set (caches the result for speed)
Returns the column name by index number
Returns the value of a set param by name (key)
Returns JSON built from result array
Return the built result array
Sets up all the various portions needed for query generation from $_REQUEST
Setup paging for SQL
Dynamic function for setting up ordering Argument format is:
NOTE this does not match the built-in DataTables filtering which does it word by word on any field. It's possible to do here, but concerned about efficiency on very large tables, and MySQL's regex functionality is very limited Dynamic function for setting up filtering Argument format is:
Sets up SQL queries based on collected data
Run queries and build result array
Returns the resulting JSON when the object is used as a string
Language | php |
Version | 0.0.0 |
Git URL | https://github.com/nullivex/lib-datatables |
License | GPL-3.0 |
Description | PHP Interface for jQuery Datatables (http://datatables.net). Simple standalone, non-framework based. |
Keywords |