Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get filtering params for jquery datatable(datatables.net)?

I'm using jquery DataTables (from datatables.net) with server-side processing and ColumnFiltering add-on. I need to add a callback which will compute subtotals based on filtered data. In order to achieve this I want to make a separate ajax call. How can I extract the current ajax parameters?

like image 700
Alex Avatar asked Dec 11 '22 14:12

Alex


2 Answers

Assign datatable object to a var on creation, for example:

var oTable = $("selector").dataTable({...});`

Later use this:

var params = oTable.oApi._fnAjaxParameters(oTable.dataTable().fnSettings());

it returns all ajax parameters which would be sent in a normal data loading request for datatables. Make your ajax call like this :

$.post("url",$.param(params),function(response){....});
like image 192
Alex Avatar answered Mar 08 '23 15:03

Alex


If you're using DataTables 1.10 (the current version as of this answer), this is now a lot easier to access with the ajax.params() method.

Example from http://datatables.net/reference/api/ajax.params()

var table = $('#example').DataTable( {
    ajax: "data.json",
    serverSide: true
} );

table.on( 'xhr', function () {
    var data = table.ajax.params();
    alert( 'Search term was: '+data.search.value );
} );
like image 39
MrDerp Avatar answered Mar 08 '23 14:03

MrDerp