• Resolved aggk

    (@aggk)


    Hi,

    Is it possible to only show the 8 latest rows (ordered by a date column) from a table on a certain page, via shortcode?
    …another page would show the whole table (via “default” shortcode)

    Thanks!

Viewing 15 replies - 1 through 15 (of 17 total)
  • Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    This is a bit tricky, due to the sorting of dates…
    You could instruct the DataTables JS library to do an initial sorting on the date column, by adding this to the “Custom Commands” text field on the table’s “Edit” screen:

    "order": [ [ 0, "asc" ] ]
    

    where 0 would define that the sorting shall happen for the first column (counting starts with 0).

    Then, for the “default” Shortcode, you’d have to use

    [table id=123 datatables_custom_commands="" /]
    

    to turn the sorting off there.
    This will however only work after adding this line of code to your theme’s “functions.php” file:

    add_filter( 'tablepress_disable_custom_commands_shortcode_parameter', '__return_false' );
    

    Regards,
    Tobias

    Thread Starter aggk

    (@aggk)

    Thank you, the sorting worked great!

    Is it possible to only show the 8 latest rows (without pagination)?
    …I guess I could simply hide pagination with css but if it’s a table with up to 1000 rows would it mean these rows are loaded unneccessary in the background at all?

    …is there any recommended max limit on how large/how many row and columns should be used?

    Thanks!

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    unfortunately, I don’t know a nice way to achieve this without pagination — if the sorting still needs to be done. Can you maybe do the sorting already on the “Edit” screen?

    And no, there’s no such recommendation. It will always depend on the type and amount of data, and the server configuration (for speed etc.).

    Regards,
    Tobias

    Thread Starter aggk

    (@aggk)

    Ok, thank you!

    Would you say that it sounds like a bad idea to only show the 8 latest rows from a sorted table with up to 1000 rows (only 4 columns) on my front page.
    (on my tests on a staging version it runs very quick)

    …a separate page will display the whole table paginated 20 rows

    Thanks!
    /Anders

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    I guess it depends on how big the data amount in the overall table is. Sure, it would be some “waste” to load everything first here, but if it works for you, you could do it like that.

    Do you know where these rows will be in the table (before the sorting)? Always near the end or top? Or can they be anywhere?

    Regards,
    Tobias

    Thread Starter aggk

    (@aggk)

    The table will be updated through excel file import where new rows always will be added below the “last previous row”…so these rows would always be at the end.

    Thanks!

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    so actually you don’t to show the latest 8 rows (after some date sorting), but the last 8 rows of the table (because the latest rows will always be added at the end)?

    You could then maybe use the TablePress Row Order Extension from https://tablepress.org/extensions/table-row-order/ here. Please install and activate that and then try using this Shortcode on the page:

    [table id=123 row_order=reverse hide_rows=all show_rows=1-9 /]
    

    (with the correct table ID).

    Regards,
    Tobias

    Thread Starter aggk

    (@aggk)

    Thank you, that’s perfect!

    I see that I can also choose specific column to sort by.
    Does this mean only 8 rows are actually queried/loaded if I set pagination to 8?
    (it doesn’t matter if I use a table with 1000 rows)

    Thanks!

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    yes, but that sorting won’t help here, because it can’t sort dates, unfortunately (except if they are in yyyy/mm/dd format).

    And yes, this solution should mean that only the 8 actual rows are loaded.

    Regards,
    Tobias

    Thread Starter aggk

    (@aggk)

    I think yyyy/mm/dd -format will be possible

    Thank you for your help!

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

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

    Best wishes,
    Tobias

    Thread Starter aggk

    (@aggk)

    Hi again,

    …just one more on this. Is there any way to use the same table on different pages but with different settings?
    perhaps through parameters or programmatically:
    Set different pagination numbers and disable javascript functionality on one page?

    Thanks!

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    yes, you can do all that with Shortcode parameters, see https://tablepress.org/faq/documentation-shortcode-table/

    Regards,
    Tobias

    Thread Starter aggk

    (@aggk)

    Hi again,

    Could you please give an example on setting pagination number with shortcode parameters?
    …I could only find “datatables_paginate” which seem to be a boolean value?

    Thanks!

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    ah, the other parameter is not documented that nicely, sorry…
    Please use

    [table id=123 datatables_paginate_entries=4 /]
    

    Regards,
    Tobias

Viewing 15 replies - 1 through 15 (of 17 total)

The topic ‘8 latest rows?’ is closed to new replies.