Asa Carter
Asa Carter

Reputation: 2225

Datatables 1.10 modify custom HTML param to send to server

How do I modify a custom HTML variable to send to the server after dataTables has been initialized?

I can send custom data using the ajax paramater before dataTables has been initialized.

I have a custom filter that I want to use add data to the request after dataTables has been initialized and then redraw the data.

Upvotes: 2

Views: 688

Answers (1)

Gyrocode.com
Gyrocode.com

Reputation: 58900

You can use ajax.data to specify a custom parameter sent to the server, see the example below.

$('#example').DataTable({
    "ajax": {
        "url": "data.json",
        "data": function (d){
            d.example_select = $('#example-select').val();
        }
    }
});

ajax.data callback function will be called every time DataTables requests data from the server.

To reload data from the server after your filter changes, you can use ajax.reload() function, for example:

$('#example-select').on('change', function(){
    $('#example').DataTable().ajax.reload(); 
});

See this JSFiddle for demonstration.

Upvotes: 2

Related Questions