• Resolved Brian

    (@bwold)


    Tobias, great work on this plugin. I hope I’m not missing an obvious answer here. In any event, thanks in advance.

    We’re pulling in a member list in CSV that comes from a separate source, and we only want to display members who haven’t opted out of the list. In the source CSV, the column is “OPT_OUT” and the values are 1 (yes, opt out) and 0 (okay to display). Therefore, we want to only display those members where the OPT_OUT column equals 0.

    So I’m working with the Table Row Filters premium plugin, but I need to only search in that one column.

    I didn’t see it in the documentation, but filters also includes a filter_columns parameter. After many attempts, I finally figured out the syntax.

    [table id=1 filter="0" filter_columns="35" /]

    Seems obvious now, but having hidden a number of other columns from our source CSV, it took a while to realize that the column number is counted based on the total columns in the source, not just the visible ones. And I’m embarrassed to say how many attempts I made using OPT_OUT.

    So, we’re good, except the filter parameter doesn’t seem to like a value of zero. If I set the above to filter=”1″, I get the 35 members who have opted out, but set it to filter=”0″ and I get all records — ones and zeroes.

    Am I missing something?

    https://wordpress.org/plugins/tablepress/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Brian

    (@bwold)

    By the way, not in the documentation that I could see, but these are the parameters the addon uses:

    filter [the search string, required]
    filter_full_cell_match [defaults to false]
    filter_case_sensitive [defaults to false]
    filter_columns [defaults to all, or a column number, or numbers (e.g. 1,3,15)]

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    Ah, that’s a tricky one 🙂 Nice find!

    The PHP code for the extension uses the PHP empty() function (see http://php.net/empty ) to check if the filter attribute was set with a not-empty value. (If it was, there’s nothing for the filter to do, so it can bail early.)
    Unfortunately, the empty() function also recognizes the "0" string as empty — that’s however exactly the filter parameter that you want.

    Fortunately, fixing this is easy: Just replace the line

    if ( empty( $render_options['filter'] ) )

    in the filter_rows function with

    if ( '' == $render_options['filter'] )

    Regards,
    Tobias

    Thread Starter Brian

    (@bwold)

    Okay, I’m so not a developer, and I get itchy hacking code. Apologies in advance if I’ve broken any PHP rules, but the edit below seems to work. Please advise if I’ve missed something:

    Edit to wp-content/plugins/tablepress-row-filter/tablepress-row-filter.php, Line 98 (I added the second check for not zero):

    if ( empty( $render_options['filter'] ) && ( $render_options['filter'] ) !== '0' )

    Again, love this product!

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    that idea will also work, but it’s slightly more complicated.
    You can actually remove a pair of ( and ) if you want:

    if ( empty( $render_options['filter'] ) && $render_options['filter'] !== '0' )

    You can either use that or use the shorter version that I posted above.

    Regards,
    Tobias

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Using Filter addon with only one column’ is closed to new replies.