Server-side Datatables library for CodeIgniter4 PHP framework CodeIgniter4-DataTables is CodeIgniter4 Library to handle server-side processing of DataTables jQuery Plugin via AJAX option by using Query Builder CodeIgniter 4
For more complete example and demo please visit Documentation here
- Codeigniter 4.x
- jQuery DataTables v1.10.x
Use composer to install CodeIgniter4-DataTables into your project :
composer require hermawan/codeigniter4-datatables
This is simple basic code just write DataTable::of($builder)
call method toJson()
for output
$builder
is CodeIgniter build-in Query Builder object.
Controller :
use \Hermawan\DataTables\DataTable;
public function ajaxDatatable()
{
$db = db_connect();
$builder = $db->table('customers')->select('customerNumber, customerName, phone, city, country, postalCode');
return DataTable::of($builder)->toJson();
}
You can initialize using Model
instead Query Builder
This is simple example basic code
Controller :
use \Hermawan\DataTables\DataTable;
use \App\Models\CustomerModel;
public function ajaxDatatable()
{
$customerModel = new CustomerModel();
$customerModel->select('customerNumber, customerName, phone, city, country, postalCode');
return DataTable::of($customerModel)->toJson();
}
Javascript :
$(document).ready(function() {
$('#table').DataTable({
processing: true,
serverSide: true,
ajax: '<?php echo site_url('customers/ajaxDatatable'); ?>'
});
});
For more complete example and demo please visit Documentation here