1

I'm using DataTable with yadcf plugin and I want to override send parameters to match my API on server.

For example: I have column Order, it's third column in columns array and I want to send parameter called orderSearch instead of columns[2].search.value.

How can I do this? How can I manipulate parameters?

Gyrocode.com
  • 57,606
  • 14
  • 150
  • 185
Bardr
  • 2,319
  • 2
  • 12
  • 21

1 Answers1

2

Use ajax.data option to manipulate parameters sent to the server.

For example:

$('#example').DataTable({
  "processing": true,
  "serverSide": true,
  "ajax": {
    "url": "/script.php",
    "data": function(d){
        d.orderSearch = d.columns[2].search.value;
    }
  }
});

Also you can construct and return your own object which will not be merged with default DataTables response object. See this example for demonstration.

Gyrocode.com
  • 57,606
  • 14
  • 150
  • 185
  • But how can I prevent sending parameters from DataTables and only send my custom parameters ? Because on the site I see only the ability to add data, not to prevent sending default parameters from DataTables. Can you show example code ? Thanks ! – Bardr Apr 12 '17 at 18:48
  • 1
    @Bardr, please read the documentation referenced, especially about using [`function`](https://datatables.net/reference/option/ajax.data#function) as option value. You can construct and return your own object which will not be merged with default DataTables response object. See [this example](https://jsfiddle.net/hbem11sw/1/) for demonstration. – Gyrocode.com Apr 13 '17 at 03:48