Wepetables will help you to use jQuery Datatables in server side with CodeIgniter4.
This is a wrapper class/library inspired and based on Ignited Datatables found at https://github.com/IgnitedDatatables/Ignited-Datatables for CodeIgniter 3.x.
- Easy to use. Generates json using only a few lines of code.
- Support for table joins (left, right, outer, inner, left outer, right outer).
- Able to define custom columns, and filters.
- Editable custom variables with callback function support.
- jQuery 1.5+
- DataTables 1.10+
- CodeIgniter 4.x "Reactor"
To install the library please type this on your console
composer require wepe/wepetables
if you're using --no-dev
package on your codeigniter, use this command
composer require wepe/wepetables --update-no-dev
Declare the following code in the controller that will use Wepetables.
use wepe\Wepetables;
HTML
<table id="myDataTable">
<thead>
<tr>
<th>id</th>
<th>title</th>
<th>date</th>
</tr>
</thead>
</table>
JavaScript
$(document).ready(function(){
$('#myDataTable').DataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": '<?=base_url('home/getdata');?>',
"type": "POST"
}
});
});
Controller
public function getdata(){
$mytable = new Wepetables();
$mytable->select('id, title, date');
$mytable->from('mytable');
$generated = $mytable->generate();
return $this->response->setJSON($generated);
}
MIT License.