Category Archives: datatable

jQuery Datatable reload()

Example:

Reference:

  1. https://datatables.net/reference/api/ajax.reload()
  2. https://stackoverflow.com/questions/42905454/datatables-ajax-reload-loses-page

Datatable with buttons

Download with extensions

https://datatables.net/download/

HTML

Javascript

 

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: