Search - tweaking?

Search - tweaking?

RickDrewRickDrew Posts: 1Questions: 0Answers: 0
edited August 2010 in General
The search seems to default to "or" - example - If I enter:

Fred 22

I see all records with Fred or 22.

But what I want to see is Fred AND 22. However the search is pretty literal - if I try and use quoted, or an AND or any other operator, it searches for that text.

Is there a way so the search defaults to an exact match, so if I enter Fred 22, only a record that actually has "Fred 22" displays?

Thanks

Rick

PS - FANTASTIC product!

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi Rick,

    The search should be operating as an AND search - is it possible that the '22' is being picked up somewhere else in the row (in the HTML, or as part of a larger string or something like that). If you search for "2.0 1.8" in my demo table ( http://datatables.net/ ) then you should see the AND operation in action.

    To tweak the search, what you can do is to unbind the event handler that DataTables puts onto the search box and then attach your own (which calls fnFilter), making use of regular expressions if you wish.

    Regards,
    Allan
  • iuliandumiuliandum Posts: 70Questions: 0Answers: 0
    Allan,

    How can I do this smart search (search "2.0 1.8") from your demo table, in server-side datatables?

    Thanks!
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    You would need to recreate the regex logic that I use in DataTables in the server-side script - have a look in the function _fnFilterCreateSearch() for the logic. Basically for the string "one two three" you need to create a regular expression like: ^(?=.*?\bone\b)(?=.*?\btwo\b)(?=.*?\bthree\b).*$

    However - you will need to concatenate all of the columns in your DB for that to be effective. And regex can be quite slow on some databases... long and short - it's not easy to do (but it is possible).

    Allan
This discussion has been closed.