Pass parameters to server
Pass parameters to server
Hi,
i am using below code to pass value of dropdown,so that table gets refreshed according to the value
Datatable initialisation:
$('#administrationData')
.dataTable({
"responsive": true,
"info": false,
"searching": false,
"iDisplayLength": 10,
"bFilter": false,
"bLengthChange": false,
"aoColumns": [
{ mData: 'Status' },
{ mData: 'UpdatedDate' },
{ mData: 'UpdatedBy' },
{
responsivePriority: 2,
bSearchable: false,
bSortable: false,
mRender: function (data, type, full) {
return AdminActionColumn(full);
}
}
]
,
"ajax": {
type: "Get",
"url": url,
"data": function (d) {
return $("#Dropdwnlist").val();
},
"dataSrc": ""
}
});
Reload Code:
$('#administrationData').DataTable().ajax.reload(null, false).draw();
i am not receiving table default parameters when i do this
Kindly help
Thanks
This question has accepted answers - jump to:
Answers
What default parameters? You aren't using server-side processing, so DataTables doesn't need to send any parameters.
Allan
hi Allan,
Below code would give you more clear picture
Datatable initialisation:
$('#administrationData')
.on('preXhr.dt', function (e, settings, data) {
debugger
data.id = $("#dropdown").val();
data.sEcho = data.draw;
data.iDisplayLength = data.length;
data._iDisplayStart = data.start;
data.iColumns = data.columns.length;
data.sSortDir_0 = data.order[0].dir;
data.iSortCol_0 = data.order[0].column;
data.iSortingCols = data.order.length;
data.sColumns = ",,,,,,,,,,,,";
return data; //data;
})
.dataTable({
"ajax": {
"type": "POST",
"url": url,
"dataSrc": ""
},
"responsive": true,
"info": false,
"processing": true,
"searching": false,
"bServerSide": true,
"iDisplayLength": 10,
"bFilter": false,
"bLengthChange": false,
"aoColumns": [
{ mData: 'Status' },
{ mData: 'UpdatedDate' },
{ mData: 'UpdatedBy' },
{
responsivePriority: 2,
bSearchable: false,
bSortable: false,
mRender: function (data, type, full) {
return AdminActionColumn(full);
}
}
]
Reload Code:
$('#administrationData').DataTable().ajax.reload(null, false).draw();
i am doing server side processing
default parameters here i meant is sEcho,_iDisplayStart,_iDisplayLength, etc. once i put ajax parameter in datatable initialization, i wont get the default parameters on server
Thanks
Yes, your new code in the second post does use server-side processing.
Can you give me a link to the page showing the issue please. I don't see why you wouldn't be getting the server-side processing parameters with the above.
Allan
Hi allan,
Thank you for your time.
Below code worked for me
Datatable Initialisation
Reload Code:
adminTable.api().ajax.reload();
Add "ajax" parameter in datatable initialization changes default parameters, i took the same of and it worked
Thanks again
Happy Coding..
Yes - the
preXhr
option can be used to send data to the server. The other option is to useajax.data
.Allan