I am using jQuery DataTables (http://www.datatables.net/) to display some tabular data. The search/ filter is a powerful feature. Although if multiple keywords are searched in the table the search filters only the already filtered data.
For instance in the example here - http://jsfiddle.net/illuminatus/2j0Lz5or/1/
If the keywords are searched like 10 99
it does not yield any result. I want the search to display all the results/ rows containing all the keyword which are searched or entered.
Searching 10 99
would display rows 1, 5 and 6.
Technically, the search should be an 'OR' search.
Would appreciate any help.
EDIT: The search should be an 'OR' search.
AND-filter (include rows where all search words is present). This custom filter overrides the builtin filtering process. Each column in each row is compared with each search word.
forked fiddle -> http://jsfiddle.net/9d097s4a/
OR-filter (include rows where at least one of the search words is present). This is another approach, mostly an attempt to streamline this answer above. Instead of playing with
oSearch
and hardcoded search terms, the default filtering event is replaced with an event that tokenizes the search phrase and then performs an advancedfnFilter()
. As optional experiment, the search is now only performed when the user hits enter - it feels somehow more natural.see demo -> http://jsfiddle.net/2p8sa9ww/
The same but triggering search on "every" key press instead of pressing enter:
I got this working by using regEx search. I used the following regEx to search throughout the table for keywords
10 99
^(?=.*?(10|99)).*?
Forked fiddle - http://jsfiddle.net/illuminatus/2j0Lz5or/6/
Ref: http://datatables.net/forums/discussion/12062/filtering-jquery-datatable-using-regular-expression
Updated for Datatables 1.10
//Search field in new location