Category Archives: datatable

Datatable Complete Example

Controller

Model

Javascript (index.js)

AjaxResponse Trait

 

Datatable with Row Details (Child Row)

Example:

https://datatables.net/examples/api/row_details.html

Data Format (with column name)

https://datatables.net/examples/ajax/data/objects.txt

Columns Config:

https://datatables.net/reference/option/columns

JS example:

 

Show custom error messages from server side

The key is to add a listener to “xhr.dt” event before initialize datatable plugin.

Server side:

 

Reference:

  1. https://datatables.net/reference/event/xhr

Custom http error response in JSON

Server side (PHP):

Client (with datatable):

Result in Chrome dev tool:

Datatable Server Side Processing (Laravel)

Javascript:

Config:

 

Controller:

Model:

 

Localization of datatable

Localization file:

Sample code:

Display priority:

  1. Localization file
  2. paginate option
  3. aria

Reference:

Datatable Server Side Processing (CI)

Javascript:

Server:

Column config

 

Controller

Ajax Response

Model

 

Select All Checkboxes

Reference: