Tableslgniter is an addins base on CodeIgniter4. It will help you use jQuery Datatables in server side mode.
If you want to get CodeIgniter3 version of Tableslgniter you can go to this git repository.
Visit the sample website and read user guide.
TablesIgniter 基於 CodeIgniter4 。它將可以幫助你在 使用 server side mode 中使用 jQuery Datatables。
如果你希望取得 CodeIgniter3 版本的 Tableslgniter 你可以前往這個 git儲存庫 。
- CodeIgniter Framework 4.*
- Composer
composer require monken/tablesigniter
Declare the following code in the controller that will use TablesIgniter.
use monken\TablesIgniter;
<table id="firstTable">
<thead>
<tr>
<th>id</th>
<th>title</th>
<th>date</th>
</tr>
</thead>
</table>
$('#firstTable').DataTable({
"aoColumnDefs": [{
"bSortable": false,
"aTargets": [ 0,1,2 ]
}],
"order":[],
"serverSide":true,
"searching": false,
"lengthChange":false,
"ajax":{
url:"<?=base_url('home/firstTable')?>",
type:'POST'
}
});
public function firstTable(){
$model = new HomeModel();
$table = new TablesIgniter();
$table->setTable($model->noticeTable())
->setOutput(["id","title","date"]);
return $table->getDatatable();
}
-
Calling the "setTable()" method must pass in a Query Builder object. TablesIgniter relies on the database query content defined by this object. This object is usually declared in the Model.
-
When calling the "setOutput()" method, the array must be passed in. The order of the array will affect the order of the data presented by DataTables. The definition of the string must be the same as the field name of the result queried by "setTable()".
-
Calling "getDatatable()" will get the json string that meets the requirements of jQuery DataTables.
public function noticeTable(){
$builder = $this->db->table("news");
return $builder;
}
You are free to use all the methods of Query Builder to meet all your requirements for database query. Finally, you must return the objects generated by Query Builder.