Can I pass array of values as fnServerParams in jQuery DataTable

Can I pass array of values as fnServerParams in jQuery DataTable

JugramJugram Posts: 10Questions: 0Answers: 0
edited July 2013 in General
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.

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    you mean something like this?

    [code]
    "fnServerParams": function (aoData) {
    for (i in filterarray) aoData.push(filterarray[i]);
    }
    [/code]
  • JugramJugram Posts: 10Questions: 0Answers: 0
    No fbas, what you suggest is same as i am doing. I am trying to find a way where i can do something like this

    [code]"fnServerParams": function (aoData) {
    filterarray;
    }[/code]
This discussion has been closed.