Multiple elements in filter
Multiple elements in filter
I was wondering if there was a way to allow users to input multiple elements the table search, using either a coma and/or a plus sign to separate them.
I know you can do the individual column search, and even allow regex in it, but I mean the filter for the whole table.
Also, I dont necessarily need a full regex search ability, rather just multiple elements that are separated out, meaning I dont want them to have to type something like (something|else)
to search for two strings, just something, else
or something + else
Thanks!
This question has accepted answers - jump to:
Answers
Heres my code this far
But that doesnt work, since it executes a search on each search... turtles all the way down
Looks to m like it should work. On the reg ex search example page,
http://datatables.net/examples/api/regex.html
I put in "acosta|chang" and checked the regex box without smart search and it worked.
I trust that line 7 is outputting the sort of regex you expect from your search. The problem might be in any spaces carried into the regex.
" acosta | chang " does not match on the example page.
Try stripping out spaces
That example page is from external search inputs, mines from the search input on datatables..
If you search, it executes that code, which does a search, which executes that code.. which does a search.... etc
D'oh. Of course. Look at your code. You've hooked into the search.dt event and then you call it. You need to move that hook to a keyup on the input box.
Isnt there a way to just filter the search text?
I don't know if there is a way to take control of that native search box. The easiest way around that issue would be to just make a new input box.
You can use my yadcf plugin for that too, use initMultipleColumns , it can aacpet
text
/select
/ 'multi_select' , you can combine it with theselect2
/chosen
for a better ui too, see it in actionI know I just wanted to have the default search input do it, didnt want to have to hide it and show another one
@daniel_r I am using it, and it does search for multiple elements in each column, works great!
If you really want to leverage the built in input box, you can use JQuery to remove any events tied to it and then apply your own function as an event.
Hm, very good point.