basic search field: boolean operators

basic search field: boolean operators

beginner_beginner_ Posts: 55Questions: 2Answers: 0
edited August 2011 in General
In the basic search/filter field of data tables, is it possible to somehow combine 2 search terms? Like "red AND blue" or "green OR yellow"?

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    "OR" is easy to do if you use regular expression matching "green|yellow"

    you could simulate an AND, but it's more convoluted in regexp "green.*yellow|yellow.*green" (matches text with green ... yellow or yellow ... green)

    the AND would be tough to expect your users to input on their own, so you might need to parse their input and convert to another form before passing it to DataTables.

    ---

    in order to enable regular expression matching, see http://www.datatables.net/api#fnFilter
  • beginner_beginner_ Posts: 55Questions: 2Answers: 0
    Ok, how would i do that to alter the behavior of the default global search field of datatables?
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    Probably by not using the default search field and input your own in it's place. This way you can control the actions/events of this search field.

    You can put arbitrary div elements into the sDom, so instead of including the default filter 'f', input your own div, and fill it (using JQuery/javascript) with your textbox that has code attached to events (onkeyup or on change or detecting enter key, etc. however you want to trigger your search)



    instead of "sDom": 'lfrtip', use "sDom": 'l<"search">rtip'
    See: http://www.datatables.net/ref#sDom

    there will now be a div placed in the DOM with id="search" (use CSS to style it, i.e. make it inline if you want)

    add textbox to it with $('#search').html("");
    attach event listeners to textbox: $('#searchbox').click( function() { ... } );
This discussion has been closed.