• Resolved Pluh

    (@pluh)


    I’m using TablePress and I installed the DataTables Sorting Plugin 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 6 years, 9 months ago by Pluh.
    • This topic was modified 6 years, 9 months ago by Pluh.
Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    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://www.ads-software.com/support/topic/date-order-6/ which deals with a very similar scenario.

    Regards,
    Tobias

    Thread Starter Pluh

    (@pluh)

    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 TobiasBg

    (@tobiasbg)

    Hi,

    that might actually work, yes.

    Regards,
    Tobias

    Thread Starter Pluh

    (@pluh)

    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 TobiasBg

    (@tobiasbg)

    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

    (@pluh)

    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 6 years, 8 months ago by Pluh.
    • This reply was modified 6 years, 8 months ago by Pluh.
    Plugin Author TobiasBg

    (@tobiasbg)

    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

    (@pluh)

    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 TobiasBg

    (@tobiasbg)

    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

    (@pluh)

    Here it is:
    https://thishosting.rocks/table-test/
    Password is: [redacted]

    Plugin Author TobiasBg

    (@tobiasbg)

    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

    (@pluh)

    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 6 years, 8 months ago by Pluh.
    Plugin Author TobiasBg

    (@tobiasbg)

    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 here in the plugin directory. Thanks!

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Custom Sorting’ is closed to new replies.