Title: Sorting Numbers from Shortcode
Last modified: July 27, 2023

---

# Sorting Numbers from Shortcode

 *  Resolved [potez](https://wordpress.org/support/users/potez/)
 * (@potez)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/sorting-numbers-from-shortcode/)
 * Hello, I am loving your plugin to help me display a team leaderboard for a fundraising
   event. Basically, I will be showing a list of team names that I masked for privacy
   for this post. But I will be showing their names in column 1 and the dynamically
   calculated team total dollars raised in column two. I am pulling that number 
   using a shortcode that is working great with your tables. My issue is sorting
   because the team totals will be changing as people give money to their teams,
   and I would need to manually resort 10-20x a day for the next month if I cannot
   have a sorting solution in place. I did some reading on datatables sort order
   custom commands but the handful I tried are not working. I know that me having
   a shortcode potentially complicates this a bit, but once the page is loaded and
   I click on the datatables Tablepress sort arrows, the column sorts perfectly 
   by the dollar value, so the sort functionality works. I would just like to always
   have the page load with the top dollar amount at the top sorting to the lowest
   amounts. Is there a custom command I am missing or you know of to make this work.
   Thank you so much for this! If I can get the sort to consistently show, I am 
   going to take this a step further and get your column rank addon, but I just 
   need to know this sorts properly before going deeper into this. Thank you for
   your time and for a fantastic plugin!
 * [https://ibb.co/J7pXWfV](https://ibb.co/J7pXWfV)
   [https://ibb.co/S3qTxDy](https://ibb.co/S3qTxDy)
    -  This topic was modified 2 years, 10 months ago by [potez](https://wordpress.org/support/users/potez/).
    -  This topic was modified 2 years, 10 months ago by [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/).

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

 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/sorting-numbers-from-shortcode/#post-16928627)
 * Hi,
 * thanks for your post, and sorry for the trouble.
 * Here, it would indeed be a possibility to sort the table upon loading of the 
   page by the visitor. From what I can see from the screenshots, all that should
   be needed is to add this to the “Custom Commands” text field in the “Table Features
   for Site Visitors” section on the table’s “Edit” screen:
 *     ```wp-block-code
       "order": [ [ 1, "desc" ] ]
       ```
   
 * Here, the `1` indicates that the second column should be sorted (counting the
   columns starts with 0 for the first column, in this JavaScript code).
 * (The [Counter Column](https://tablepress.org/modules/datatables-counter-column/)
   module should then work nicely here as well, it will automatically create that
   1, 2, 3, etc. ranking.)
 * I hope this helps 🙂
 * Best wishes,
   Tobias
 *  Thread Starter [potez](https://wordpress.org/support/users/potez/)
 * (@potez)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/sorting-numbers-from-shortcode/#post-16928638)
 * Thank you so much for replying! That worked for me! I tried something very similar
   to that before, but maybe I needed to keep the sorting checkbox checked for it
   to work because I did not have it checked earlier when I was adding custom commands.
   But whatever the reason, it is working amazingly now and I will just test it 
   for a couple days but I think this is going to be a huge timesaver for us. I 
   really appreciate the quick reply!
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/sorting-numbers-from-shortcode/#post-16929263)
 * Hi,
 * good to hear that this helped! Yes, the “sorting” checkbox needs to be active
   for this to work.
 * Best wishes,
   Tobias
 *  Thread Starter [potez](https://wordpress.org/support/users/potez/)
 * (@potez)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/sorting-numbers-from-shortcode/#post-16971505)
 * Hi Tobias,
 * One more question on the sorting. It was working great for me to sort where I
   had my shortcode in a column always doing some work behind the scenes to calculate
   an updated total for my fundraising event. The shortcode is counting all the 
   donations we have for a specific team, and it spits out a number. These numbers
   have been sorting great for the start of our event, but I just noticed something
   as our donations went over $1,000.
 * Donations larger than $1,000 caused the order to change where now a $4,000 donation
   is sorted as if it is just a donation that starts with 4 (i.e. sorts where 400
   would sort). I attached an image showing how it is sorting right now. I installed
   that datatables plugin you offer for sorting, but I am not sure what to do with
   it or if that would help fix it. I know I will have many donations in the 2,000-
   20,000 range, so I need them to sort properly with the thousands separator maybe
   being the culprit.
 * How it is sorting now: [https://ibb.co/Gt39573](https://ibb.co/Gt39573)
 * My code that was working up until thousands started happening: “order”: [ [ 1,“
   desc” ] ]
 * Thank you for your help thus far!
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/sorting-numbers-from-shortcode/#post-16971784)
 * Hi,
 * indeed, that data format is likely the issue here. As you already installed the
   Extension, please try this extended “Custom Command:
 *     ```wp-block-code
       "columnDefs": [ { "type": "formatted-num", "targets": [ 1 ] } ], "order": [ [ 1, "desc" ] ]
       ```
   
 * Regards,
   Tobias
 *  Thread Starter [potez](https://wordpress.org/support/users/potez/)
 * (@potez)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/sorting-numbers-from-shortcode/#post-16971931)
 * That did it. You’re amazing! Thank you so much for the help again!
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/sorting-numbers-from-shortcode/#post-16972116)
 * 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](https://wordpress.org/support/plugin/tablepress/reviews/#new-post)
   in the plugin directory. Thanks!

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

The topic ‘Sorting Numbers from Shortcode’ 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/)

 * 7 replies
 * 2 participants
 * Last reply from: [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * Last activity: [2 years, 10 months ago](https://wordpress.org/support/topic/sorting-numbers-from-shortcode/#post-16972116)
 * Status: resolved