Replacing the default filter criteria

Replacing the default filter criteria

hammersmashhammersmash Posts: 15Questions: 0Answers: 0
edited November 2011 in General
I am trying to replace the default filter criteria. I want to keep the filter bar and all the plumbing, but I only want to filter rows that don't match my custom filter.

Specific case: Trying to keep all values unless a value is entered that matches a value in the list.

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    Does this help? http://stackoverflow.com/questions/406230/regular-expression-to-match-string-not-containing-a-word

    and use fnFilter with reg expression param set true.
  • hammersmashhammersmash Posts: 15Questions: 0Answers: 0
    That would get all the rows that don't match the values, but if the value was present then it would be filtered out.

    I suppose I could compare the list returned against the total list and if the lists didn't match I would know that the value is present. I could then re-filter for the value and display those results in that case.
  • hammersmashhammersmash Posts: 15Questions: 0Answers: 0
    edited November 2011
    Actually, should fnFilter "" return all the values? That should also fire the custom filter?

    Yes to both.
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    oSearch is the initialisation parameter you are looking for in this case - you need to set oSearch.sFilter (see the example code in the documentation) to set a default filter. You can combine that with regex if you wish to refine the search a bit further - but that's how the default filter is set :-)

    > Actually, should fnFilter "" return all the values? That should also fire the custom filter?

    As you say - yes to both. "" means no filter (if you want to match empty strings you would need to use regex) and fnFilter will indeed cause DataTables to apply all filters :-)

    Allan
  • hammersmashhammersmash Posts: 15Questions: 0Answers: 0
    Thanks for the help once again Allan. I'm confused about the oSearch.sFilter, doesn't seem to be in the docs under oSearch? Did you mean sSearch? Sorry, I'm a little slow at this stuff.

    I ended removing the default filter element via sDom and adding my own which would fire fnFilter with an empty search term. I added the custom filter using $.fn.dataTableExt.afnFiltering. The reason I did this was to filter 2 tables from one search bar. Only the first table was filtered unless the search item matched something in the second table, then only the second table was filtered.

    Not sure if this was the best method, any further advice? If not, thanks again anyways!
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    oSearch: http://datatables.net/ref#oSearch

    [code]
    $(document).ready( function() {
        $('#example').dataTable( {
            "oSearch": {"sSearch": "Initial search"}
        } );
    } )
    [/code]

    Or in Javascript dotted object notation - oSearch.sSearch (sorry it should have been sSearch rather than sFilter that I put before!).

    TO filter multiple tables, this plug-in API method might be of use to you: http://datatables.net/plug-ins/api#fnFilterAll

    Allan
  • hammersmashhammersmash Posts: 15Questions: 0Answers: 0
    Cool, I'll have to try that plug-in out. Looks like it would have been better than what I did ><
This discussion has been closed.