Server-side individual column search

Server-side individual column search

jazjaz Posts: 16Questions: 3Answers: 0
edited December 2014 in Free community support

I'm having a difficult time implementing server-side processing with individual column searches. From my understanding, the value to search on for each column should be accessed in POST using columns[i][search][value], but I'm unsure how to set that variable.

I'm using MVC (CakePHP). I have a script implemented in my controller that returns the properly encoded data, when I use a hard-coded value (as opposed to the one that I want to be passed in from the view). Since I can get and encode data and it shows up in my table, I doubt that my table or script are part of the problem at this point.

Here is a link to the debugger output: http://debug.datatables.net/ofaqik

Here is my js:

$(function(){
var table = $("#departureTable").DataTable({
'serverSide': true,
'ajax' : {
"url" : '/CustomersDepartures/filterData',
"type" : 'POST',
"columns" : [
{"name": "product_type"}
]
}
});

$("#column1_search").on ('change', function(){
table.column('product_type')
.search($(this).val())
.draw();
});
});

$("#column1_search") refers to the following select input:

<select name="data[Product][product_type]" id="column1_search">
<option value=""></option>
<option value="1">Bicycle Tours</option>
<option value="2">Walking and Hiking Tours</option>
</select>

(I have no idea why newlines aren't coming through in my code.... sorry about that. :/)

Should the search value be passed as a POST variable and if so, how do I set it in my view?

Answers

  • jazjaz Posts: 16Questions: 3Answers: 0

    Ok, figured out that it's actually the name of the column that isn't getting set correctly. When I changed table.column('product_type') to table.column(0), it works correctly.

    Anyone have any thoughts about what I'm doing wrong when trying to name columns?

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    he value to search on for each column should be accessed in POST using columns[i][search][value], but I'm unsure how to set that variable.

    Use the column().search() method to set the search value. Once set, call draw() to instruct DataTables to redraw the table and get the latest data (since you are using server-side processing).

    Regards,
    Allan

  • jazjaz Posts: 16Questions: 3Answers: 0

    Hey Allan-

    Thanks for commenting. I actually was using column().search() and it wasn't working. When I changed it from using names to using the column number, it worked just fine. Still not sure why it was doing that, but I've continued using column numbers.

This discussion has been closed.