Title: Custom Sorting
Last modified: March 5, 2018

---

# Custom Sorting

 *  Resolved [Pluh](https://wordpress.org/support/users/pluh/)
 * (@pluh)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/custom-sorting-5/)
 * I’m using TablePress and I installed the DataTables Sorting Plugin [https://tablepress.org/extensions/datatables-sorting-plugins/](https://tablepress.org/extensions/datatables-sorting-plugins/)
 * I have this weird situation right now. I’m using DataTables in my TablePress 
   table with the sorting feature enabled.
 * Right now, these columns DO get sorted:
    – Numbers with a letter at the end (
   5K, 10K) only – Currency only ($5, $10) – Numbers only mixed with text only (
   5, 10, Free) – Numbers mixed with text in the same cell (5 Frees, 10 Frees) So
   all of those get sorted, except: – Numbers with a letter at the end and text 
   only (5K, 10K, Free) – so this one doesn’t get sorted. What should I used to 
   get it sorted? I tried sorting them by the “natural” and “absolute” type, but
   it doesn’t work.
    -  This topic was modified 8 years, 2 months ago by [Pluh](https://wordpress.org/support/users/pluh/).
    -  This topic was modified 8 years, 2 months ago by [Pluh](https://wordpress.org/support/users/pluh/).

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

 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/custom-sorting-5/#post-10041680)
 * Hi,
 * thanks for your post, and sorry for the trouble.
 * The problem with that format likely is that there’s no number in the “Free” value.
   The sorting algorithm however would require that (as it strips all characters).
 * An alternative approach for such custom search terms is [https://wordpress.org/support/topic/date-order-6/](https://wordpress.org/support/topic/date-order-6/)
   which deals with a very similar scenario.
 * Regards,
    Tobias
 *  Thread Starter [Pluh](https://wordpress.org/support/users/pluh/)
 * (@pluh)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/custom-sorting-5/#post-10041973)
 * Would adding a number in a div tag and hiding it via CSS help? Basically the 
   sorting plugin will have a number to work with.
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/custom-sorting-5/#post-10041995)
 * Hi,
 * that might actually work, yes.
 * Regards,
    Tobias
 *  Thread Starter [Pluh](https://wordpress.org/support/users/pluh/)
 * (@pluh)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/custom-sorting-5/#post-10042918)
 * That doesn’t seem to help either. Should I add any custom sorting through the
   sorting plugin?
 * I also have a file size column and use only numbers like 5GB, 10GB… I tried sorting
   them by file-size but they still won’t sort properly. I tried adding a space 
   like 5 GB, 10 GB…but it still doesn’t work.
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/custom-sorting-5/#post-10043284)
 * Hi,
 * Can you please post a link to the page with the table where this problem happens,
   so that I can take a direct look? Thanks!
 * Regards,
    Tobias
 *  Thread Starter [Pluh](https://wordpress.org/support/users/pluh/)
 * (@pluh)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/custom-sorting-5/#post-10047268)
 * Actually I just found out what’s causing the issue. It actually sorts them based
   on the first digit of the actual number. So they are sorted like this:
 * 10000
    20 312412 5
 * Instead of the actual full number. What should I do in such cases?
 * columnDefs: [{ “type”: “natural”, “targets”: 2 }] doesn’t work.
 * I haven’t published my post yet so I cannot send you a link, sorry.
 * Adding a hidden (via CSS) number does work, but I’d rather find a better solution.
   I avoid hiding elements via CSS since google and other crawlers will crawl it
   anyway.
    -  This reply was modified 8 years, 2 months ago by [Pluh](https://wordpress.org/support/users/pluh/).
    -  This reply was modified 8 years, 2 months ago by [Pluh](https://wordpress.org/support/users/pluh/).
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/custom-sorting-5/#post-10047798)
 * Hi,
 * it’s sorting after the first digit only because it’s sorting this columns as 
   text/strings, and not as numbers. This happens because there is also text/characters
   in that column.
 * Instead of using “natural”, please also try “num-fmt”. And keep in mind that 
   the 2 in your “targets” means third column, just in case.
 * Regards,
    Tobias
 *  Thread Starter [Pluh](https://wordpress.org/support/users/pluh/)
 * (@pluh)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/custom-sorting-5/#post-10048488)
 * Actually after trying columnDefs: [{ “type”: “num-fmt”, “targets”: 2 }], the 
   whole sorting function seems to disappear from the whole table. So I can’t even
   sort them in any way after using that (the arrows are missing)
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/custom-sorting-5/#post-10048501)
 * Hi,
 * I think it would really be the best if I could take a direct look at this. Can
   you maybe publish this as a test page somehow?
 * Regards,
    Tobias
 *  Thread Starter [Pluh](https://wordpress.org/support/users/pluh/)
 * (@pluh)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/custom-sorting-5/#post-10048635)
 * Here it is:
    [https://thishosting.rocks/table-test/](https://thishosting.rocks/table-test/)
   Password is: [redacted]
    -  This reply was modified 8 years, 2 months ago by [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/).
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/custom-sorting-5/#post-10049387)
 * Hi,
 * thanks for the link! The problem here is that you are not using the proper quotation
   marks `"` (from typing via keyboard), but typographically nicer ones `“` (which
   you get from copy/pasting the code from somewhere).
 * Note the difference between (the wrong)
 *     ```
       columnDefs: [{ “type”: “num-fmt”, “targets”: 2 }]
       ```
   
 * and (the correct)
 *     ```
       columnDefs: [{ "type": "num-fmt", "targets": 2 }]
       ```
   
 * Now, in your case, you will probably also run into problems because of the toolips
   that you are showing (with the little “i” icon). For this column, the best approach
   should really be what I mentioned in my first reply.
 * Regards,
    Tobias
 *  Thread Starter [Pluh](https://wordpress.org/support/users/pluh/)
 * (@pluh)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/custom-sorting-5/#post-10049602)
 * Oh man I didn’t even notice those.
 * Thank you for your help!
 * Not sure if you can, but please remove the link I posted earlier. I can’t edit
   my post anymore
    -  This reply was modified 8 years, 2 months ago by [Pluh](https://wordpress.org/support/users/pluh/).
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [8 years, 2 months ago](https://wordpress.org/support/topic/custom-sorting-5/#post-10050618)
 * Hi,
 * no problem, you are very welcome! 🙂 Good to hear that this helped!
 * No, sorry, I can’t remove the URL, as I’m not a moderator here.
 * Best wishes,
    Tobias
 * P.S.: In case you haven’t, please [rate TablePress](https://wordpress.org/support/plugin/tablepress/reviews/)
   here in the plugin directory. Thanks!

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

The topic ‘Custom Sorting’ 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/)

 * 13 replies
 * 2 participants
 * Last reply from: [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * Last activity: [8 years, 2 months ago](https://wordpress.org/support/topic/custom-sorting-5/#post-10050618)
 * Status: resolved