Load ajax data with custom parameters
Load ajax data with custom parameters
viandante
Posts: 22Questions: 10Answers: 1
Hi to all!
In my datatable i pass few custom parameters (ex: values of input fields).
But if i change the value of the input fields, and reload the table, the new values are not taken...
<script type="text/javascript">
tblPreventivi = $('#dt_basic').DataTable({
"processing": true,
"serverSide": true,
"order": [[0, "desc"]],
"ajax": {
url: "?modulo=Preventivo&action=getPreventiviNew&ajxRq=1",
data: {
"dtStart": $("#dtStartAlternate").val(),
"dtEnd": $("#dtEndAlternate").val(),
"provincia": $("#selProvincia").val(),
"inviati": $("input[name=preventiviinviati]:checked").val()
}
},
"columns": [
{data: {
_: "id.display",
sort: "id.tosort"
}},
{data: {
_: "datapreventivo.display",
sort: "datapreventivo.timestamp"
}},
{data: {
_: "datamodifica.display",
sort: "datamodifica.timestamp"
}},
{data: "nome"},
{data: "email"},
{data: "telefono"},
{data: "citta"},
{data: "provincia"},
{data: "opzioni"},
],
"sDom": "<'dt-toolbar'<'col-xs-12 col-sm-3 col-sm-offset-9'f>>r" +
"t" +
"<'dt-toolbar-footer'<'col-sm-3 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-9'>p>",
"autoWidth": true,
"preDrawCallback": function() {
// Initialize the responsive datatables helper once.
if (!responsiveHelper_dt_basic) {
responsiveHelper_dt_basic = new ResponsiveDatatablesHelper($('#dt_basic'), breakpointDefinition);
}
},
"columnDefs": [
{"orderable": false, "targets": 8},
{"orderable": false, "targets": 1}
],
"rowCallback": function(nRow) {
responsiveHelper_dt_basic.createExpandIcon(nRow);
},
"drawCallback": function(oSettings) {
responsiveHelper_dt_basic.respond();
},
"language": {
"url": "accessories/DT-IT.txt"
}
});
</script>
The initial value of the dtStart, dtEnd etc.. parameters is "", and it's ok, but when i change the value:
<script type="text/javascript">
$(document).on("change", ".datepicker", function(event) {
tblPreventivi.ajax.reload();
});
</script>
the new value are not taken...
How i can do this?
Datatables 1.10
Thanks in advance.
Massimo
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
try this
http://datatables.net/reference/option/ajax.data
i apologize for the formatting, but the link gives you a more readable example.
I found the solution, a function for the data...
But this solution don't work with the pipeline example...
Not sure why @sumit25's answer was rejected - it is exactly what I would suggest myself and is correct.
Regarding pipelining - if you want to use it with pipelining you would need to modify the pipelining code a little to add your data to each request.
Allan
Sorry, i read a wrong answer from sumit25... it's the right answer...