monken/tablesigniter

CodeIgniter4 starter app

v1.2.1 2021-05-02 17:02 UTC

This package is auto-updated.

Last update: 2024-04-29 04:21:06 UTC


README

Latest Stable Version Total Downloads License

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儲存庫

造訪範例網站與使用指南

Install

Prerequisites

  1. CodeIgniter Framework 4.*
  2. Composer

Composer Install

composer require monken/tablesigniter

Use Library

Declare the following code in the controller that will use TablesIgniter.

use monken\TablesIgniter;

Quick Start

HTML

<table id="firstTable">
    <thead>
        <tr>
            <th>id</th>
            <th>title</th>
            <th>date</th>
        </tr>
    </thead>
</table>

JavaScript

$('#firstTable').DataTable({
    "aoColumnDefs": [{ 
        "bSortable": false,
        "aTargets": [ 0,1,2 ] 
    }],
    "order":[],
    "serverSide":true,
    "searching": false,
    "lengthChange":false,
    "ajax":{
        url:"<?=base_url('home/firstTable')?>",
        type:'POST'
    }
});

Controller

public function firstTable(){
    $model = new HomeModel();
    $table = new TablesIgniter();
    $table->setTable($model->noticeTable())
          ->setOutput(["id","title","date"]);
    return $table->getDatatable();
}
  1. 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.

  2. 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()".

  3. Calling "getDatatable()" will get the json string that meets the requirements of jQuery DataTables.

Model

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.