Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is the sAjaxSource parameter in datatables?

According to datatables website,

sAjaxSource
You can instruct DataTables to load data from an external source using this parameter (use aData if you want to pass data in you already have). Simply provide a url a JSON object can be obtained from. This object must include the parameter 'aaData' which is the data source for the table.

Now, to me (an amateur with Ajax and JSON), this is gibberish.

I want my datatable to paginate, and load new entries using Ajax each time the table is re-sorted or the next page is chosen (instead of loading all entries up front)

Apparently this "url a JSON object can be obtained from" is needed if I want to set the bServerSide option to true

Is there anyone that can explain this concept to me?

like image 759
Marco Prins Avatar asked Nov 01 '22 03:11

Marco Prins


1 Answers

In server-side processing you can choose either of two ways:

  1. Serve JSON from the same URL, which you use to show HTML page with a table (page with table is on www.example.com/table and AJAX call to www.example.com/?sEcho=1&andOtherParametersHere) - you do not need specify sAjaxSource, because datatable's script joins the parameters to the existing URL.

  2. Serve JSON from URL that is different from one you use to show HTML page with table (so page with table is on www.example.com/table and AJAX call to www.another.com/?sEcho=1&andOtherParametersHere) - you must specify sAjaxSource to www.another.com.

like image 161
Lukasz Koziara Avatar answered Nov 12 '22 21:11

Lukasz Koziara