Can I pass array of values as fnServerParams in jQuery DataTable
Can I pass array of values as fnServerParams in jQuery DataTable
I am using jQuery DataTables to display data on my form. I have a requirement where I need to send multiple parameters to filter data.
Currently I am using:
[code]$('.datatable').dataTable({
"sDom": "<'row'<'span3'l><'span6'f>r>t<'row'<'span5'i><'span4'p>>",
"bServerSide": true,
"sAjaxSource": //myurl,
"bProcessing": true,
"sPaginationType": true,
"bSort": true,
"iDisplayLength": 20,
"fnServerParams": function (aoData) {
aoData.push({ "name": "chk1", "value": true});
},
"fnCreatedRow": function (nRow, aData, iDataIndex) {
// Do stuff with row data
},
"bFilter": false,
"bDestroy": true
});[/code]
where chk1, chk2,.. are checkboxes and for simplicity sake, lets presume, user checked it as true. Now in my Code, I can easily retrieve chk1 value but my requirement is what if user chooses 3 or 4 checkboxes (I will have 7-8 checkboxes on my page)? I want to pass all these 3-4 choosen checkboxes value in an array to code(MVC).
What i am doing now is, getting all choosen checkboxes data in array as:
[code]var filterarray = [];
filterarray .push({ "name": "chk1", "value": true});
filterarray .push({ "name": "chk2", "value": true});[/code]
Now how do i pass filterarray as a fnServerParams value? any help will be appreciated.
Currently I am using:
[code]$('.datatable').dataTable({
"sDom": "<'row'<'span3'l><'span6'f>r>t<'row'<'span5'i><'span4'p>>",
"bServerSide": true,
"sAjaxSource": //myurl,
"bProcessing": true,
"sPaginationType": true,
"bSort": true,
"iDisplayLength": 20,
"fnServerParams": function (aoData) {
aoData.push({ "name": "chk1", "value": true});
},
"fnCreatedRow": function (nRow, aData, iDataIndex) {
// Do stuff with row data
},
"bFilter": false,
"bDestroy": true
});[/code]
where chk1, chk2,.. are checkboxes and for simplicity sake, lets presume, user checked it as true. Now in my Code, I can easily retrieve chk1 value but my requirement is what if user chooses 3 or 4 checkboxes (I will have 7-8 checkboxes on my page)? I want to pass all these 3-4 choosen checkboxes value in an array to code(MVC).
What i am doing now is, getting all choosen checkboxes data in array as:
[code]var filterarray = [];
filterarray .push({ "name": "chk1", "value": true});
filterarray .push({ "name": "chk2", "value": true});[/code]
Now how do i pass filterarray as a fnServerParams value? any help will be appreciated.
This discussion has been closed.
Replies
[code]
"fnServerParams": function (aoData) {
for (i in filterarray) aoData.push(filterarray[i]);
}
[/code]
[code]"fnServerParams": function (aoData) {
filterarray;
}[/code]