Title: Sort Shortcode for widget?
Last modified: August 20, 2016

---

# Sort Shortcode for widget?

 *  Resolved [SENO_Media](https://wordpress.org/support/users/seno_media/)
 * (@seno_media)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/sort-shortcode-for-widget/)
 * 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/](http://wordpress.org/extend/plugins/tablepress/)

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/sort-shortcode-for-widget/#post-3416306)
 * 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
 *  Thread Starter [SENO_Media](https://wordpress.org/support/users/seno_media/)
 * (@seno_media)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/sort-shortcode-for-widget/#post-3416342)
 * 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!
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/sort-shortcode-for-widget/#post-3416347)
 * 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
 *  Thread Starter [SENO_Media](https://wordpress.org/support/users/seno_media/)
 * (@seno_media)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/sort-shortcode-for-widget/#post-3416371)
 * 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!
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/sort-shortcode-for-widget/#post-3416373)
 * 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
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/sort-shortcode-for-widget/#post-3416379)
 * Hi,
 * good news, I was able to develop that Extension 🙂
    You can find it here: [http://tablepress.org/extensions/table-row-order/](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
 *  Thread Starter [SENO_Media](https://wordpress.org/support/users/seno_media/)
 * (@seno_media)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/sort-shortcode-for-widget/#post-3416381)
 * YOU ARE A WIZARD!!!!!!
 * Thank you so much!!!
 * I will donate for sure!
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/sort-shortcode-for-widget/#post-3416382)
 * 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!

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Sort Shortcode for widget?’ is closed to new replies.

 * ![](https://ps.w.org/tablepress/assets/icon.svg?rev=3192944)
 * [TablePress - Tables in WordPress made easy](https://wordpress.org/plugins/tablepress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/tablepress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/tablepress/)
 * [Active Topics](https://wordpress.org/support/plugin/tablepress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/tablepress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/tablepress/reviews/)

## Tags

 * [Short Code](https://wordpress.org/support/topic-tag/short-code/)
 * [sort](https://wordpress.org/support/topic-tag/sort/)

 * 8 replies
 * 2 participants
 * Last reply from: [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * Last activity: [13 years, 4 months ago](https://wordpress.org/support/topic/sort-shortcode-for-widget/#post-3416382)
 * Status: resolved