Forums

WP-Table Reloaded
Master Table Filtering (7 posts)

  1. stevegayler
    Member
    Posted 4 months ago #

    Hi Tobias,

    I adore this plugin so much ( ihave previously donated)

    I have a question, I have one central table that has 4000 lines in it.

    I need to create about 300 wordpress pages which contain elements of the table.

    It is a discography for a band so for eg The Master table is

    ID Artist Single \ Album Title Country CatNo Notes Image Link

    Now my question is, is there a way to create a filtered list based on Artist and Title, but to then display that filtered list without those 2 columns.

    If I can work this out,my life just became much easier!

    Kind Regards

    Steve

    http://wordpress.org/extend/plugins/wp-table-reloaded/

  2. TobiasBg
    Member
    Posted 4 months ago #

    Hi Steve,

    thanks for your post.

    Yes, this should be possible with the "Filtering Extension", that you can find on my website, see http://tobias.baethge.com/2010/03/extension-6-showing-only-rows-that-match-a-filter/
    This will basically give you a new Shortcode parameter, which you can then use in the Shortcode on those 300 pages, to only get the rows from the table that match the filter word.

    Best wishes,
    Tobias

  3. stevegayler
    Member
    Posted 4 months ago #

    Thanks Tobias I will take a look, but the important element is then can I hide 2 columns as the query columns will not need to be shown?

    Many thanks as always.

    Steve

  4. stevegayler
    Member
    Posted 4 months ago #

    Tobias, ignore that, i've just seen how its done.

    Wish id asked the question weeks ago, but hey I still think you have saved me a load of time!

    Can you force the filter word to only be searched in a particular column?

    Once i'm done i'd like to show you the implementation to see if you can give any further suggestions on making it better.

    Mnay thanks - looks like another donation may have to be on its way soon.

    Steve

  5. TobiasBg
    Member
    Posted 4 months ago #

    Hi,

    yes, hiding the columns with the filter word is indeed possible, as you have already found out :-)

    Restricting the filtering to just a particular column is not possible right now (the code would have to be extended for this), but it should not really be necessary in general: If there's trouble with certain filter words (that are "found too often"), the best solution might be to add a new (hidden) column for the filter word of each row. The advantage of such a column would be that you can use "special" filter words, and to not get too many positive results from the other columns, you could prefix the filter words there.

    Regards,
    Tobias

  6. stevegayler
    Member
    Posted 4 months ago #

    Hi Tobias,

    So I have split the table down into about 7 sections which are manageable and all have uploaded fine.

    I have setup the extensions plugin whcih activated OK and added the code for filtering a table. I am also using the code to hide 3 columns.

    So far on this test table, here :
    I have set for 3 columns to be hidden and for the filter word to be ANGEL, one of the song titles. The result is a table that has the columns hidden but the filter doesnt seem to have activated.

    Here's the plugin code I have used:

    <?php
    /*
    Plugin Name: WP-Table Reloaded Extensions
    Plugin URI: http://tobias.baethge.com/wordpress-plugins/wp-table-reloaded-english/extensions/
    Description: Custom Extensions for WP-Table Reloaded
    Version: 1.0
    Author: YOU, Tobias Baethge
    */

    /**
    * Show only rows that match the "filter" parameter value/contained logical expression
    */
    function wp_table_reloaded_filter_rows( $output_options, $table_id, $table ) {
    // early exit if no "filter" parameter given
    if ( empty( $output_options['filter'] ) )
    return $output_options;

    $filter = $output_options['filter']; // from the Shortcode parameter "filter"

    // && is the passed value for &&
    if ( false !== strpos( $filter, '&&' ) ) {
    $compare = 'and';
    $filter = explode( '&&', $filter );
    } elseif ( false !== strpos( $filter, '||' ) ) {
    $compare = 'or';
    $filter = explode( '||', $filter );
    } else {
    $compare = 'none'; // single filter word
    $filter = array( $filter );
    }

    foreach ( $filter as $key => $string ) {
    // remove HTML entities and turn them into characters, escape/slash other characters
    $filter[ $key ] = addslashes( wp_specialchars_decode( $string, ENT_QUOTES, false, true ) );
    }

    $row_match = false;
    foreach ( $table['data'] as $row_idx => $row ) {
    if ( 0 == $row_idx && $output_options['first_row_th'] )
    continue;

    $found = array();
    foreach ( $filter as $key => $string ) {
    $found[ $key ] = in_array( $string, $row );
    }

    switch ( $compare ) {
    case 'none':
    case 'or':
    if ( in_array( true, $found ) ) // at least one word was found / only filter word was found
    $row_match = true;
    else
    $output_options['hide_rows'][] = (string)$row_idx;
    break;
    case 'and':
    if ( ! in_array( false, $found ) ) // if not (at least one word was *not* found) == all words were found
    $row_match = true;
    else
    $output_options['hide_rows'][] = (string)$row_idx;
    break;
    }
    }

    // if search term(s) was/were not found in any of the rows, all rows need to be hidden
    // but only if first row is used as table head
    if ( ! $row_match && $output_options['first_row_th'] ) {
    $row_idx = 0;
    $output_options['hide_rows'][] = (string)$row_idx;
    }

    return $output_options;
    }

    /**
    * Add "filter" as a valid parameter to the [table] Shortcode
    */
    function wp_table_reloaded_shortcode_parameter_filter( $default_atts ) {
    $default_atts['filter'] = '';
    return $default_atts;
    }

    /**
    * Register necessary Plugin Filters
    */
    add_filter( 'wp_table_reloaded_frontend_output_options', 'wp_table_reloaded_filter_rows', 10, 3 );
    add_filter( 'wp_table_reloaded_shortcode_table_default_atts', 'wp_table_reloaded_shortcode_parameter_filter' );

    ?>

    The Page that the code is on appear like this:

    [table id=505 hide_columns="3,4,5" filter="ANGEL" /] and here is the page itself http://www.eurythmics.me.uk/test-3/

    I have also unchecked the Cache Table Output option on the table.

    I have also flushed our own caching plugin on the site.

    What have i missed Tobias!!!

  7. TobiasBg
    Member
    Posted 4 months ago #

    Hi,

    thanks for your post.

    The PHP code looks ok... I'm not really sure why this is not working. It might be the best and quickest way, if I could take a direct look at the admin area on your site.
    Can you contact me via email? (The address is in the main plugin file "wp-table-reloaded.php".)

    Regards,
    Tobias

Reply

You must log in to post.

About this Plugin

About this Topic