Custom Search box - AND/OR logic operators

Custom Search box - AND/OR logic operators

MrMoneMrMone 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

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    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

  • MrMoneMrMone Posts: 4Questions: 1Answers: 0

    could you provide a snippet of code?

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    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

  • MrMoneMrMone Posts: 4Questions: 1Answers: 0

    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

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    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. the input) and you can then add your event handlers etc to that, and have it positioned around the table through the layout option.

    Allan

  • MrMoneMrMone Posts: 4Questions: 1Answers: 0

    I resolved using the '#dt-search-0' tag. thanks anyway

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    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

Sign In or Register to comment.