How fnFilter for an empty string?

How fnFilter for an empty string?

jadymitchelljadymitchell Posts: 11Questions: 0Answers: 0
edited February 2011 in General
I've searched quite a bit on this, with no success. How do I filter for an empty string? This does not work:

oTable.fnFilter( '', 4);

Any help would be appreciated.

Replies

  • 28.vivek.s28.vivek.s Posts: 69Questions: 0Answers: 0
    [code]oTable.fnFilter( ' ', 4);[/code]

    Thanks,
    Vivek
  • jadymitchelljadymitchell Posts: 11Questions: 0Answers: 0
    Thanks, but I tried that before and it didn't work

    My data is a column of dates (e.g.,2/2/2010). If I do

    [code]oTable.fnFilter('2/2/2010', 4)[/code]

    it filters to that date. But if the date column is empty and I filter for empty, no luck.
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Passing a blank string into fnFilter means "no filter". Passing a space in as Vivek suggests will filter on a space. To filter on empty data you need to use a regular expression. fnFilter( '^$', 4, true, false ); should do it.

    Allan
  • jadymitchelljadymitchell Posts: 11Questions: 0Answers: 0
    edited February 2011
    Allan,

    I can't thank you enough for your quick response and wonderful project (I will be donating!). However, the regex doesn't seem to work either. Here is a sample of the json I have:

    [code]["1525","Kenneth ","Jones","08\/17\/2010","","CRIMINAL","asmith",""],["1511","Don","Hamilton","07\/22\/2010","08\/09\/2010","CRIMINAL","asmith","Nolle Pros"],[/code]

    Running this code:

    [code]fnFilter( '^$', 4, true, false );[/code]

    does not return the first record. Help!
  • jadymitchelljadymitchell Posts: 11Questions: 0Answers: 0
    Sorry! I was missing the name of the table. This:

    [code]oTable.fnFilter( '^$', 4, true, false );[/code]

    works fine. Thanks!
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    Trying to find empty strings.

    For whatever reason, reg expressions are not working on my install. Even tried searching .* and got nothing. Is there anything that would disable the reg ex? Text filters work fine, but special chars are not being interpreted as special.

    I double checked the database and the values are empty strings, not null. Have banished NULL from those columns.

    [code]
    oTable.fnFilter(value, get_column_number(colname), true, false);
    console.log(colname, '|'+value+'|', get_column_number(colname));
    [/code]
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    .* is going to match everything, so thee won't be any filtering applied.

    The code jadymitchell posted looks just fine - can you do something like that:

    [code]
    oTable.fnFilter( '^$', get_column_number(colname), true, false );
    [/code]

    That will match empty strings.

    Allan
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    I see what the problem was: since I'm using server side processing, it's also passing the match criteria to the server. I edited my php server side to check for "^$" and bRegex_# = true and change the LIKE clause to = ''

    I was just unclear if the filtering was running locally even if the rest of the processing is server-side.

    thanks.
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    If you are using server-side processing then all of the data processing is done by the server. DataTables in that mode is just a dumb display and event handler. Good to hear you got it sorted.

    Allan
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    Thanks. I finally got some money deposited into my paypal account this morning and made a small but well-deserved donation.
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Thank you :-). It is much appreciated!

    Allan
This discussion has been closed.