Setting ajax.data dynamically oustide instance
Setting ajax.data dynamically oustide instance
kabeza
Posts: 14Questions: 5Answers: 0
I have the following var which initializes a Datatable with these settings
var tablaDatos = $('#tablaDatos').DataTable({
"language": {
"url": "spanish.json"
},
"processing": true,
"serverSide": true,
"serverMethod": "post",
"ajax": {
"url": '/data_json',
"data": {
"filtro_tipo": "",
"filtro_herramienta": "",
"filtro_destino": "",
}
},
"bFilter": true,
"bAutoWidth": false,
"ordering": true,
});
I have a select with some static options
When user chooses an option (select.change) I want to filter the table with the selected option and reload the ajax query, etc.
$('#myselect').on('change', function() {
console.log("Filter: " + this.value);
tablaDatos.ajax.data = { "filtro_tipo" : this.value };
console.log(tablaDatos);
tablaDatos.ajax.reload();
// tablaDatos.draw();
});
Is this the correct way to set ajax.data ?
Console.log shows the correct value, but it is not sending the ajax.data in the $_POST array ...
What could be wrong? Thanks
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi @kabeza,
I'm not sure that you can set
ajax.data
like that, I'd be very surprised if that works. The best bet would be to haveajax.data
as a function (see the examples on that page) and setfiltro_tipo
(and the others) based on a property or variable.Hope that does the trick,
Cheers,
Colin
Hi @colin
Yes, that did the trick. Thanks!