• Resolved jakkoni

    (@jakkoni)


    Hi, thank for your answer,and sorry for the trouble.

    I need the last 10 rows added to the table to be displayed on the main page, and under these ten rows there is a button (view the full table) with a transition to another page where the full table is displayed

    Question: how on the first page to display the last 10 rows added to the table on and display the full table on the second page. Thank you very much!

    • This topic was modified 4 years, 11 months ago by jakkoni.
    • This topic was modified 4 years, 11 months ago by jakkoni.
    • This topic was modified 4 years, 11 months ago by jakkoni.
    • This topic was modified 4 years, 11 months ago by jakkoni.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    For this, you’d need a bit of extra code, that can generate that shortened version of the table. Please add this to the “functions.php” file of your theme:

    add_shortcode( 'short-table', 'jakkoni_tablepress_table_last_x_rows' );
    function jakkoni_tablepress_table_last_x_rows( $atts ) {
    	$atts = (array) $atts;
    	$number_rows = tablepress_get_table_info( array(
    		'id' => $atts['id'],
    		'field' => 'number_rows',
    		'format' => 'raw',
    	) );
    
    	$from = $number_rows - (int) $atts['last_rows'];
    	$to = $number_rows;
    
    	$atts['hide_rows'] = 'all';
    	$atts['show_rows'] = "1,{$from}-{$to}";
    
    	return tablepress_get_table( $atts );
    }

    Then, on the main page, add a Shortcode like this:

    [short-table id=123 last_rows=10 /]
    

    Then, create another page where you add the Shortcode for the full table,

    [table id=123 /]
    

    (change 123 to the table’s ID in both cases).

    Then, you can add a link or button below the Shortcode on the main page that links to the other page.

    Regards,
    Tobias

    Thread Starter jakkoni

    (@jakkoni)

    The fact is that I do not have a theme, I make a site on Elemntor canvas

    Thread Starter jakkoni

    (@jakkoni)

    Update:

    I inserted shortcode in tablepress.php without Elementor, everything works, but as soon as I click edit with Elementor, this error appears:
    https://pastenow.ru/de825ed5ca4f61d4e70fb14416c32690

    • This reply was modified 4 years, 11 months ago by jakkoni.
    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    but even with Elementor, you should have a theme ??

    This error seems to caused by Elementor evaluating the Shortcode when it shouldn’t…

    Please try this modified code:

    
    if ( ! is_admin() ) {
    add_shortcode( 'short-table', 'jakkoni_tablepress_table_last_x_rows' );
    function jakkoni_tablepress_table_last_x_rows( $atts ) {
    	$atts = (array) $atts;
    	$number_rows = tablepress_get_table_info( array(
    		'id' => $atts['id'],
    		'field' => 'number_rows',
    		'format' => 'raw',
    	) );
    
    	$from = $number_rows - (int) $atts['last_rows'];
    	$to = $number_rows;
    
    	$atts['hide_rows'] = 'all';
    	$atts['show_rows'] = "1,{$from}-{$to}";
    
    	return tablepress_get_table( $atts );
    }
    }

    Regards,
    Tobias

    Thread Starter jakkoni

    (@jakkoni)

    Thanks It works!!

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! ?? Good to hear that this helped!

    Best wishes,
    Tobias

    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘table size on different pages’ is closed to new replies.