Single Column Filter

Single Column Filter

ackerchezackerchez Posts: 6Questions: 0Answers: 0
edited December 2010 in General
I have been trying to use the search all text field but it is not suiting my needs. I have been reading about single column searching and having the "sSearch_(int)" parameters be filled in on the ajax call to the server but have not managed to implement this. How is it possible to implement the ability to choose one column from a range of columns (i.e. if you have name, phone, address, city) to pick one of them from a dropdown and then execute a search based on that dropdown (i.e. wanting to search a phone number and then entering a string to search) to the server?

Is it a matter of manipulating the data sent to the server? I feel that the "sSearch" parameters are the key here but I do not know how to populate them with the information needed.

Thanks!

Replies

  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin
    The way DataTables works with server-side processing and single column filtering is that on the client-side you call fnFilter( "string", 1 );, which on the server-side would give you "sSearch_1=string". You can then apply that to your SQL query. So this assumes some knowledge at the server-side as to what column '1' is (phone number, zip code, whatever). There is the sNames parameter which can be used to help here, although sometimes it's not needed. So really the key thing is to call fnFilter with your column search.

    Allan
  • ackerchezackerchez Posts: 6Questions: 0Answers: 0
    Hi Allan,

    Thanks for the great information. I have successfully managed to install my own searching. One issue though, I tried to disable the global search box by setting "bFilter" to false but this kills the ability to filter anything, period (fnFilter API call no longer works). Is there a way to hide the search all box or even replace it with my own but still preserve the ability to filter?
  • ackerchezackerchez Posts: 6Questions: 0Answers: 0
    Nevermind, figured out how to use the "SDOM" option on initialization.

    Thanks!
This discussion has been closed.