Title: Sorting columns as numeric
Last modified: February 24, 2025

---

# Sorting columns as numeric

 *  Resolved [jimlord](https://wordpress.org/support/users/jimlord/)
 * (@jimlord)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/sorting-columns-as-numeric/)
 * When a user clicks to sort a column, it is cycling through what appears to be
   a text ascending, numeric ascending, and text descending. This can most easily
   be seen in the “Division II” standings on the page at [https://collegestunt.org/rankings/](https://collegestunt.org/rankings/)
   where we have numbers into the teens. The initial table is correct, as we have
   it sorted properly in the original table. If one sorts by team alphabetically
   and then goes back to sort the ranking, it puts it in order of “1, 10, 11, 12…
   18, 2, 3, 4” when first clicked. If they click again, it goes descending, and
   then click again to get it how it should be seen. Is there a way to force a sort
   to always be numeric? (hope I got that right)
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fsorting-columns-as-numeric%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Thread Starter [jimlord](https://wordpress.org/support/users/jimlord/)
 * (@jimlord)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/sorting-columns-as-numeric/#post-18325583)
 * I actually just added another column on a test table and it looks like it’s actually
   cycling through ascending, descending, and then original order as displayed. 
   We just happen to have it in the right order originally so that’s what is showing
   up. That can be seen by sorting the two different ranking columns here: [https://collegestunt.org/testrankings/](https://collegestunt.org/testrankings/)
   
   I have TablePress Pro.
    -  This reply was modified 1 year, 3 months ago by [jimlord](https://wordpress.org/support/users/jimlord/).
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/sorting-columns-as-numeric/#post-18325838)
 * Hi Jim!
 * Thanks for your post and sorry for the trouble!
 * Your observation is correct: The sorting is “ascending” -> “descending” -> “original
   order” and so on.
 * Now, the cause for the wrong order here is that some cells actually contain text
   and not just numbers, namely “NR” or things like “… (tie)”. This switches the
   sorting algorithm to text string sorting, where “10” is then sorted between “
   1” and “2”.
 * The question now is how you would like to treat this. My personal feeling would
   be to actually simply turn off sorting for that Rank column (and also the second
   column, with the team logo). For that, you could add this to the “Custom Commands”
   text field on the table’s “Edit” screen:
 *     ```wp-block-code
       columnDefs: [  { orderable: false, targets: [ 0, 1 ] },],
       ```
   
 * Best wishes,
   Tobias
 *  Thread Starter [jimlord](https://wordpress.org/support/users/jimlord/)
 * (@jimlord)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/sorting-columns-as-numeric/#post-18328848)
 *  I started to realize that when testing some other stuff. I think my best option
   maybe to keep the numbers in one column and add any text in a second column right
   next to it and try to size those columns to be minimum width. 
   One problem I 
   found with this approach is that if I don’t have anything in the rank column,
   then that blank cell gets sorted first instead of last. I’ll play around with
   these options and if I find a good solution I’ll repost here in case anybody 
   else can use a solution. Thanks so much for always being so responsive!!! Best
   plug-in and developer on the planet.
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/sorting-columns-as-numeric/#post-18329327)
 * Hi Jim,
 * We could actually also use a custom sorting that will always keep “NR” entries
   at the bottom. However, as this concerns the TablePress premium support, I would
   please need to get you in touch via email, to the address that you can find on
   the “About” screen of TablePress on your site.
 * Best wishes,
   Tobias

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

The topic ‘Sorting columns as numeric’ 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/)

 * 4 replies
 * 2 participants
 * Last reply from: [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * Last activity: [1 year, 3 months ago](https://wordpress.org/support/topic/sorting-columns-as-numeric/#post-18329327)
 * Status: resolved