Reputation: 2225
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
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