Custom Search box - AND/OR logic operators
Custom Search box - AND/OR logic operators
MrMone
Posts: 4Questions: 1Answers: 0
Hi all, I want to modify the default search box so that it can accept AND/OR logic operators.
Example:
if I type ' cat OR dog ' in the search box I want it shows me all the records having the keyword cat or the keyword dog (or both).
if I type 'cat AND dog 'then I want that it shows just the records having both cat and dog at the same time.
could you help me?
Thanks in advance
Answers
Sounds great - the way to do it is with
search()
where you provide a function as the search term. Your function would need to parse the logic string and apply that to the data given to the function (i.e. it is called once for each row).That is not something that I have done yet, but it it perfectly possible to do.
Allan
could you provide a snippet of code?
Custom development of a logic filter like this is something that would be covered by the support plans. I expect it would take me a couple of hours to get the search logic for something like that right, so I'm afraid it is beyond the scope of the free support I provide.
Allan
Thank you for the response.
One more thing, how can I recognize the html tag of the search box?
I didn't define it in my code and I don't know how to track it
If you are building a feature such as this, you wouldn't hook into the
input
that DataTables displays. Instead, create a custom feature plug-in that adds the DOM elements you need (i.e. theinput
) and you can then add your event handlers etc to that, and have it positioned around the table through thelayout
option.Allan
I resolved using the '#dt-search-0' tag. thanks anyway
If you want to reuse the built in search box, make sure you unbind its own event listeners so you can add your own. Creating what you want as a feature plugin would be much more modular though.
Allan