Is it possible to allow a column to be filterable without being searchable?
Is it possible to allow a column to be filterable without being searchable?
jspath
Posts: 6Questions: 1Answers: 0
I have some hidden columns in my table that I would like to filter upon, but not be searchable by the user.
Is this possible? Or do I need to implement a custom search input that only searches particular columns?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
The only way I can figure to do this is to have the hidden columns marked as searchable, but implement the dataTables search input myself, and restrict it to the user searchable columns.
In DataTables searchable and filterable are basically the same thing (actually, technically is always a filter that DataTables does, but the search terminology is used for simplicity and to not conflict with
filter()
). So I'm afraid I'm not sure what you are looking for. Is it that you want to be able to search the data using the API, but the end user shouldn't be able to using the search input?If so, at the moment you are correct, there isn't a way to distinguish between the two. You would need to implement a custom search plug-in.
Allan
In the old dataTables (pre 1.10), I could mark a column with bSearchable false, while still using fnFilter on it. We'd use this to allow customers to filter on various id values, while not having the id's searchable by the user.
I'll look into the search plugin idea, but as of right now, I think implementing our own search input that will call .columns().search() so that I can limit user searches to specific columns, instead of all searchable columns.
Heh - that wasn't an intentional feature! However, this is exactly the behaviour that is implemented for
columns.orderable
whereby it removes the user's ability to order on a column, but the API can still order on that column.I think it would be correct behaviour to allow that for
columns.searchable
as well. I'll look into that for the 1.10.5 release.Thanks for flagging this up!
Allan
As it turns out, the best solution was the custom search plugin:
My idea of columns().search() didn't work, since all the columns had to match, not just 1.
One final question allan ... is it possible to limit a search plugin to a particular table? Or is the search plugin always going to be applied globally to all dataTables on the page?
Thanks for your help!
You need to check
settings.nTable
(which is the table node, wheresettings is the first parameter passed into the function). You could use
settings.nTable.id` for example to get the id of the table.Unfortunately that is currently the only way with the global filtering plug-ins. I'm going to improve that in a future release.
Allan
OK, if I check the table id and decide that I do not want to use my custom search plugin, is there an easy way to execute the default search at that point?
Just return
true
so that the custom filter isn't filtering any rows out.Allan