Support » Plugin: TablePress - Tables in WordPress made easy » Dynamic table data

  • Resolved locomo

    (@locomo)


    Is it possible to generate the data for the table dynamically rather than manually creating it in the admin area.

    I.e. I would run my own query, format the data into a suitable structure, and then pass it into your function “tablepress_print_table”.

    Is something like that possible? Sorry if I missed it but I didn’t see anything in the documentation about this.

    Thanks!

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

Viewing 5 replies - 16 through 20 (of 20 total)
  • Hi,

    The function add_filter doesn’t work for me….I probably missed something!
    In fact when I comment the line add_filter( 'tablepress_table_render_data', 'change_table' ); the table is correctly displayed …..but if I remove the comment the table disapare
    `
    add_filter( ‘tablepress_table_render_data’, ‘change_table’ );
    function change_table($table, $orig_table, $render_options )
    {
    $table_id = 55; // Table test
    if ( $table[‘id’]==55 )
    {
    $table[‘data’][1][2]=’xxx’;
    }
    return $table;
    }
    Is something should be configured to use add_filter function?

    Thks for your support

    Thierry

    • This reply was modified 6 years, 9 months ago by thierrySN.
    Plugin Author TobiasBg

    (@tobiasbg)

    Hi thierrysn,

    this is a standard WordPress function, show it should work fine.

    Now, I don’t quite understand: Are you getting error messages? Or are you just not seeing the change that your code makes?

    Regards,
    Tobias

    Hi Tobias,
    In fact the page does not appear: I get a blank page.

    add_filter ('tablepress_table_render_data', 'change_table');

    Does not work in my case and the cause is’nt the function change_table since a dummy function does not work.
    I avoided the problem by using add_filter ('tablepress_cell_content', 'change_cel', 5,4); but I know this is not the right method since I have to assign the Cells one by one .

    Regard

    Thierry

    • This reply was modified 6 years, 9 months ago by thierrySN.
    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    if you get a blank page, this ususally indicates PHP errors. I recommend setting the WP_DEBUG constant to true in the wp-config.php file, to get more error information. See e.g. https://codex.wordpress.org/Editing_wp-config.php#Debug

    Regards,
    Tobias

    Dear Mr Bäthge,

    I like your TablePress plugin – beautiful code. 🙂 I will use the responsive extension and will make a donation.

    I found this post – great to learn about the “tablepress_table_render_data” hook! I too will be using TablePress to display tables with dynamic content. I will call tablepress_print_table() in my shortcodes, when I need to display a table. I will design the tables (and perhaps add a row with headers) in your practical editor, and the rest of the rows will be calculated at run time.

    It’s a bit cumbersome to use a hook, though. It would be much more practical to just send the data as an argument to the tablepress_print_table() call. Like this, e.g., using a new “data” argument to tablepress_print_table():

    // calculated of course, not constant values
    $mydata = array(
        array( 'First row', 123, 'London' ),
        array( 'Second row', 456, 'Paris' ),
        array( 'Third row', 789, 'Rome' ),
    );
    
    tablepress_print_table( array( 'id' => '1', 'data' => $mydata ));

    TablePress reads the table from the database as usual (and the JSON in the post is unpacked), but after that the items in the “data” argument array are added to the “$table[‘data’]” array. (After some checking, of course. So that all rows have the expected number of columns and so on.) The argument is only allowed in the tablepress_print_table() call, not when using the [table] shortcode.

    Wouldn’t an extra argument like that be pretty easy to implement? I think it could be useful to many developers. I would be great if it could be added in a future version! 🙂

    Best regards

    Anders from Sweden

Viewing 5 replies - 16 through 20 (of 20 total)
  • The topic ‘Dynamic table data’ is closed to new replies.