Simple column select box for search, and "word starts with" filter
Simple column select box for search, and "word starts with" filter
Is there an easy way to add a select box next to DataTable's native search box that allows one to select the column to search, with "All" as a default. So, if you have columns, Name, Address and Phone, you would see a select box with those three, plus "All", allowing an uncluttered way to select the column(s) you want to search. (I know I can add a text box for each column - but I don't want to do that. Hoping there's a native option to enable such a thing.)
Additionally, the search filter seems to just check if the keyword(s) are present anywhere in the data. Is there an easy way to override this filter to only look for words starting with all of the keyword(s) entered? Something like: /\bKEYWORD/i, or even an option for /^KEYWORD/i, instead of what appears to be /KEYWORD/i.
Answers
Check out this very popular plugin https://github.com/vedmack/yadcf
Thanks, but as far as I can tell, that doesn't have the ability to easily select the column being searched, while still using a single search text box, nor does it search on word boundaries.
It looks like I'd have to write my own plugin to deal with this sort of thing, but, it seems like plugins can't easily use the DataTable's native search input field (the value of that field isn't passed to the plugin), instead requiring you to roll your own.
An example on how to override the global search function would be helpful.
Okay so here is something to try. Set https://datatables.net/reference/option/searching to false, this will remove native search. Utilize yadcf plugin example http://yadcf-showcase.appspot.com/dom_source_externally_triggered.html. The column_number option accepts an array, so you can configure a single text input for all columns.
So something like this i think might be a good starting point.
Also, the documentation for the plugin is inside the js file, take a look at filter_container_selector, that might be what will become your header column dropdown.