A CodeIgniter library for building a Datatables server side processing SQL query.
Links
Download Datatables_server_side.php and add it to your application/libraries directory.
From within any of your Controller methods, initialize library using the CodeIgniter's standard way. You MUST pass data as an array via the second parameter and it will be passed to the library's constructor:
$this->load->library('datatables_server_side', array(
'table' => 'customer', //name of the table to fetch data from
'primary_key' => 'customer_id', //primary key field name
'columns' => array('first_name', 'last_name', 'email'), //zero-based array of field names.
'where' => array() //associative array or custom where string
));
Once the library is loaded, you need to call the following method:
$this->datatables_server_side->process();
The method accepts two parameters which are both optional. These parameters are used to add / modify tr tag.
row_id (String)
Possible values: 'id', 'data', 'none'
Examples
$this->datatables_server_side->process('id');
//
$this->datatables_server_side->process('data'); //Default
//
$this->datatables_server_side->process('none');
//
row_class (String)
Possible values: '', 'class_name'
Examples
$this->datatables_server_side->process('none', ''); //Default
//
$this->datatables_server_side->process('none', 'class_name');
//
The following sample uses sakila dump downloaded from (https://dev.mysql.com/doc/index-other.html). You can also clone this repository and run it on your local machine to see an end to end working example.
load->helper('url');
$this->load->view('home');
}
public function load_data()
{
$this->load->library('datatables_server_side', array(
'table' => 'customer',
'primary_key' => 'customer_id',
'columns' => array('first_name', 'last_name', 'email'),
'where' => array()
));
$this->datatables_server_side->process();
}
}
First name |
Last name |
Email |
---|