WordPress.org

Ready to get started?Download WordPress

Forums

WP-Table Reloaded - Can I reference another cell? (14 posts)

  1. socialmediasorted
    Member
    Posted 3 years ago #

    Hi Tobias,

    I want to upload a master csv sheet to WP-Table Reloaded and from there each cell will send the cell data to a particular cell in another table ID.

    Is this possible at all?

    Thanks,
    Merrin

  2. TobiasBg
    Member
    Posted 3 years ago #

    Hi,

    you could achieve something like this with an additional Shortcode, which would only return a single value from another table (i.e. your master table).

    To get that Shortcode, paste the following into your theme's "functions.php":

    <?php
    
    // handle [table_cell id=123 c=4 r=5 /]
    function shortcode_handler_table_cell( $atts ) {
      global $WP_Table_Reloaded_Frontend;  
    
      $atts = shortcode_atts( array( 'id' => 0, 'c' => 0, 'r' => 0 ), $atts );
      $table_id = $atts['id'];
      $column = $atts['c'] - 1; // subtract 1 because of different array index
      $row = $atts['r'] - 1; // subtract 1 because of different array index
    
      $table = $WP_Table_Reloaded_Frontend->load_table( $table_id );
      $cell_content = $table['data'][$row][$column];
      $render = $WP_Table_Reloaded_Frontend->create_class_instance( 'WP_Table_Reloaded_Render', 'render.class.php' );
      return do_shortcode( $render->safe_output( $cell_content ) );
    }
    add_shortcode( 'table_cell', 'shortcode_handler_table_cell' );
    ?>

    Then, create your master table as usual (and find out its table ID).

    To then reference a cell from that master table, go to your new table and insert the Shortcode

    [table_cell id=5 r=2 c=4 /]

    where 5 would be the master table's ID, and r and c would mark the row and column (fourth cell of the second row in my example).

    Hope this helps!

    Best wishes,
    Tobias

  3. socialmediasorted
    Member
    Posted 3 years ago #

    Thanks for that, will let you know how we get on.

    Regards,
    MErrin

  4. socialmediasorted
    Member
    Posted 3 years ago #

    Another quick question, when I View Source any of my website pages, the whole custom CSS code for Table Reloaded shows up, we have over 200 so it is a lot of data showing and maybe a reason why our site runs slowly? Is there anyway I can hide the code?

    Thanks
    Merrin

    http://advantagetradingsystems.com

  5. TobiasBg
    Member
    Posted 3 years ago #

    Hi Merrin,

    no, you can't hide it, because then the CSS won't be applied and your tables will look like the default again :-)

    I doubt that the Custom CSS is the reason why your site is slow, but you can tweak the performance by moving everything into a CSS file.
    To do that, take all your Custom CSS and save it into a file, e.g. "tables.css", and store it in your theme's folder.
    Then, instead of the Custom CSS, just enter the following into the "Custom CSS" textfield:

    @import url("http://www.example.com/wp-content/your-theme/tables.css");

    where you will need to adjust the URL to the tables.css file.

    Best wishes,
    Tobias

  6. socialmediasorted
    Member
    Posted 3 years ago #

    Hi Tobias,
    I have been trying to paste the above code in the functions.php file but it keeps breaking the site. Any tips?

    Thanks,
    Merrin

  7. TobiasBg
    Member
    Posted 3 years ago #

    Hi Merrin,

    that code needs to go into the "Custom CSS" textfield on the "Plugin Options" screen and not in the functions.php, as it is CSS and not PHP.

    Regards,
    Tobias

  8. colinp386
    Member
    Posted 3 years ago #

    Hi I want to do something similar, and hopefully easier.
    I have a 750 row table of Open Source Software packages (like PHP. MySQL etc.) and for each package their are dependencies to other packages.

    I have the names of the dependencies in one column, how do I link the dependency to it's row in the same table, either by passing it into the search window or by taking it to the correct row.
    Even better would be the ability to filter the table to show the package and all it's dependencies ie for PHP show the rows for jpeg, glib, render, etc. :-)

    We will be making a donation to you as WP-Table Reloaded is awesome even if I can't figure this out :-)

  9. TobiasBg
    Member
    Posted 3 years ago #

    Hi,

    thanks for your question.

    Unfortunately, I don't see any way to achieve this, except for the manual way through the Shortcode that is described above :-(

    You might be able to use the Search function for this, but as I'm not that familiar with it (I didn't develop it, but just use the library in WP-Table Reloaded), I really can't help with that. You might try asking in the DataTables forums at http://www.datatables.net

    Regards,
    Tobias

  10. colinp386
    Member
    Posted 3 years ago #

    Hi Tobias;

    Many thanks for the advice, I'll have a play with the short-code as you suggest and perhaps take a look at the DataTables forum if the short code option does not provide the solution.

    I have also added the dependents to the table and that may be more elegant as when they search for PHP they now see all the dependencies

  11. iskh
    Member
    Posted 2 years ago #

    hi tobias great plugin !!

    is there some way to achieve the same functionality with template tags as [table_cell id=2 c=3 r=4]

    this works echo do_shortcode( '[table_cell id=2 c=3 r=4]' );

    but can it be something like.................
    wp_table_reloaded_print_table( "id=2&print_name=false&c=3&r=4" );

  12. TobiasBg
    Member
    Posted 2 years ago #

    Hi,

    unfortunately, I don't have a readily available template tag function for this code. You could however easily develop one, by combining the code from above with the code for the existing template tag function in the plugin.

    Now, I don't really see why you would want this, though, because the version with do_shortcode is actually pretty good and makes it more obvious what happens.

    Regards,
    Tobias

  13. iskh
    Member
    Posted 2 years ago #

    hi,
    just wanted the bit of code in a loop but do_shortcode works great too.

    thanks for the quick reply and awesome plugin

  14. TobiasBg
    Member
    Posted 2 years ago #

    Hi,

    no problem, you are welcome!

    Best wishes,
    Tobias

Topic Closed

This topic has been closed to new replies.

About this Topic