Dynamically changing filter column (bSearchable)

Dynamically changing filter column (bSearchable)

mjparmemjparme Posts: 2Questions: 0Answers: 0
edited April 2012 in General
I recently discovered DataTables and like it quite a bit. I was using two different plugins for my table, one for Filtering and one for Sorting. DataTables serves my use case great for Sorting. However, for filtering I currently have it so the user can change which column is being filtered on (it default to All columns of course). I see that DataTable has the bSearchable option where you can control which column is being used for filtering. However, is it possible to change that value dynamically and the re-filter when you change it?

For example, if I have a table of Name, Address, State, City columns when they type a value in the filter value it, by default, searches all the columns. What I have currently is I let them select any of the columns from a select box and then the filter value only applies to that column. It is no big deal if DataTables can't do this as I will keep using my other filtering plugin, but if I could replace both my sorting and filtering plugin with one plugin that would be nice.

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    > However, is it possible to change that value dynamically and the re-filter when you change it?

    Currently no - however there is no reason why a plug-in couldn't be created to allow this ability. You'd need to change the aoColumns setting for the column ( http://datatables.net/docs/DataTables/1.9.1/DataTable.models.oColumn.html#bSearchable ) and then rebuild the internally cached filter ( http://datatables.net/docs/DataTables/1.9.1/34cdb56b2c.html#_fnBuildSearchArray ) - that should about do it.

    This blog post might be of interest, as it explains how to create a plug-in API method: http://datatables.net/blog/Creating_feature_plug-ins

    Allan
  • mjparmemjparme Posts: 2Questions: 0Answers: 0
    Ok, thanks for the info. I will take a look at those links and see if I can't come with something.
This discussion has been closed.