Inverse fnFilter()?

Inverse fnFilter()?

jaycsjaycs Posts: 14Questions: 0Answers: 0
edited January 2012 in General
I'm trying to search for items in a column that don't contain a specific value. I've tried many regex's and am struggling to find a way to negate the text to match.

Normally you'd just do something like:

[code]var bMatches = !regex.match("something");[/code]

Is there a way to get fnFilter to negate the search?

Replies

  • jaycsjaycs Posts: 14Questions: 0Answers: 0
    I'm thinking about a custom filter function, but the example I see doesn't say if it's possible to bind it to a specific table (I have a number on one page) and if it can be targeted, i.e. only when I search a specific column should it be enacted:

    http://www.datatables.net/examples/plug-ins/range_filtering.html

    Essentially I want to leave the default search box to work as normally, but I have a checkbox that toggles what records are visible and aren't. This works fine on other tables, but this one has a cell value of a load of HTML that I'm struggling to do a negative match on.
  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin
    > Essentially I want to leave the default search box to work as normally, but I have a checkbox that toggles what records are visible and aren't.

    Are the values in a single column? If so, then using fnFilter and a regular expression is very much the way to go. You should also disable smart filtering (an fnFilter parameter) as DataTables uses its own regex for that, and it would interfere with your own regex.

    Allan
  • jaycsjaycs Posts: 14Questions: 0Answers: 0
    edited January 2012
    Yes, it's all on a single column. I've tried many permutations of regex's, but can't find anything that matches anything BUT the pattern.

    I had to call time on it, so I'm working around this by seeding the cell value with something I can match on, but it means extra work when I have to remove this later on as part of a persistence and re-filter scenario.

    It seems to be a common regex problem that has to be worked around by inverting the calling logic, but of course that's wrapped up in DataTable. Perhaps a parameter on fnFilter to invert the match would be useful to others?
  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin
    Filtering the table on NOT "Gecko" (in the first column): http://live.datatables.net/etibus/edit

    Allan
  • jaycsjaycs Posts: 14Questions: 0Answers: 0
    That's assuming the cell value is Gecko, I've got some long html string and I don't know the exact markup in advance. I realise there's probably the mother of all regex's to do it, but it's beyond me and the time I had, so had to bail and do the work-around above.

    Thanks anyhow Allan :)
  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin
    There is another much easier way - using a custom filter: http://datatables.net/development/filtering#row_filters . You've got the data there (in the second parameter) and you can just do an indexOf on the data for the column you want and decide if you want to pass back true or false :-)

    Allan
  • jaycsjaycs Posts: 14Questions: 0Answers: 0
    Thanks Allan, though that's a bit of a sledge-hammer of an approach from what I can see see. It applies to all tables and all searches. Ideally it could be associated to a specific table (I have more than one on screen) and for a specific column or data-type.
  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin
    Yup - its a limitation of the implementation in DataTables that :-(. It is on the radar to be fixed - possibly in 1.10, or 1.11 when I get there!

    Until then, what you can do to have it apply to only a specific table is a condition at the top of the plug-in function that will check if it is the table that you want the filter to operator on or not. If it isn't then return true (i.e. apply no filter). Is it is, then do what is needed.

    Not perfect I'm sorry to say, but possible :-)

    Allan
  • jaycsjaycs Posts: 14Questions: 0Answers: 0
    edited January 2012
    No need to explain, we're all hugely thankful to you for creating DataTables, and I for one understand only too well the demand running a project outside of your main employment puts on you! This is an amazingly comprehensive product and very well implemented, which is why I've donated this week.
  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin
    Thank you for your donation and your kind words! Both mean a lot to me!

    Regards,
    Allan
This discussion has been closed.