WordPress.org

Ready to get started?Download WordPress

Forums

TablePress
[resolved] Sort Shortcode for widget? (9 posts)

  1. SENO_Media
    Member
    Posted 1 year ago #

    Hey there, GREAT PLUGIN!! This thing is awesome!
    Basically, I have a Hockey stat table for a league.
    I set up the table with a formula for total points:

    PLAYER TEAM G A PTS
    Van Hoof, Ricebox 6 7 =C2+D2
    Wallace, Ricebox 7 6 =C3+D3
    Smith, Ricebox 8 5 =C4+D4
    And so on for roughly 150 players

    I also used the Custom commands: "aaSorting": [[4,'desc']]
    All is fine for the Table on a page but when I use a short code for a text widget
    it sorts it by the actual formula not the total points ie: [Van Hoof, Ricebox, 6, 7, 13]

    Is there any way to remedy this?

    Here is what I have for the widget: (I only want to show the top 10)
    [table id=7 show_rows="1,2,3,4,5,6,7,8,9,10,11" use_datatables="false" hide_rows="all" /]

    Thanks for any help, and thanks for a great plugin.

    http://wordpress.org/extend/plugins/tablepress/

  2. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    thanks for your question! Great to hear that you like the plugin! :-)

    Well, the problem here is that you are turning of sorting in the table in the text widget, by using the use_datatables="false" parameter. That disables the DataTables JavaScript library for this table, and with that the sorting.
    Just remove that parameter from the Shortcode and the table will be sorted correctly. Also, you can optimize your Shortcode a little bit by using a range of row numbers :-):

    [table id=7 show_rows="1-11" hide_rows="all" /]

    Regards,
    Tobias

  3. SENO_Media
    Member
    Posted 1 year ago #

    Thanks for your quick reply!

    That makes sense, is there a way to hide the sorting with the shortcode?
    It makes the widget too wide.

    Thanks also for optimization tip too!

  4. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    well, we can't turn off the sorting itself, as that's necessary for the initial sort. We can however hide the sorting arrows, to gain some space.
    To do that, please add

    .dataTables_wrapper .tablepress-id-7-small .sorting div:after,
    .dataTables_wrapper .tablepress-id-7-small .sorting_asc div:after,
    .dataTables_wrapper .tablepress-id-7-small .sorting_desc div:after {
    	content: "";
    }
    
    .dataTables_wrapper .tablepress-id-7-small .sorting,
    .dataTables_wrapper .tablepress-id-7-small .sorting_asc,
    .dataTables_wrapper .tablepress-id-7-small .sorting_desc {
        padding-right: 8px;
    }

    to the "Custom CSS". Additionally, add this parameter to the Shortcode:

    extra_css_classes="tablepress-id-7-small"

    This is to ensure that the table CSS class is unique, so that this CSS code only affects the small version of the table in the widget, but not the full version of the table.

    Regards,
    Tobias

  5. SENO_Media
    Member
    Posted 1 year ago #

    Not quite... It is still sorting the first 10 people in the table and not the overall table.

    Not a huge deal if there is not a solution just trying to save some addition mistakes! :)

    There are 156 people thats have stats

    Thanks!

  6. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    argh, yes, of course... Tricky problem.

    The show_rows/hide_rows will return the first 10 people, and that's what the sorting algorithm gets for sorting (as it doesn't even know that there are more rows).
    So, to work around this, we would either have to print the entire table to the page, let the JS sort and paginate it, and then hide the sort and pagination controls via CSS.

    The other idea would be to sort the table during the rendering process, after the formulas have been calculated, but before the show_rows/hide_rows parameters are executed. Those will then pick the first then players after sorting. The advantage of this approach would be a better performance, as we wouldn't need any JavaScript at all.
    So, I'll investigate this further, and maybe I can come up with a solution as a TablePress Extension :-) I'll post here again then.

    Regards,
    Tobias

  7. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    good news, I was able to develop that Extension :-)
    You can find it here: http://tablepress.org/extensions/table-row-order/

    1. Just download, install, and activate that as a regular WordPress plugin.
    2. Then remove the "Custom CSS" from my second to last post again, as that's no longer necessary.
    3. Go to the table's "Edit" screen, and remove the "Extra CSS class" again.
    4. Use this Shortcode for your table:

    [table id=7 show_rows="1-11" hide_rows="all" row_order="sort" row_order_sort_column="E" row_order_sort_direction="DESC" use_datatables="false" /]

    Regards,
    Tobias

  8. SENO_Media
    Member
    Posted 1 year ago #

    YOU ARE A WIZARD!!!!!!

    Thank you so much!!!

    I will donate for sure!

  9. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    :-) No problem, you are very welcome!

    And thanks for wanting to donate, I really appreciate it!

    Best wishes,
    Tobias

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic