• Resolved cbottorff89

    (@cbottorff89)


    Hello!

    I’m trying to set up a table ranking the best state for female entrepreneurs. I am using DataTables to enable sorting of columns, and by default everything is sorted with the first column numbered 1-50. However, if I sort by another column and then try to get the first column to sort 1-50 again, it doesn’t work properly. Instead of going 1, 2, 3… it sorts by 1, 10, 11, 12, 13… until it finishes the teens and then hits 2, 20, 21, 22… and so forth.

    I found this bit of code on another thread saying I could tweak it in the “Custom Commands” field, but I’m unsure of how to do so to make the table do what I want: “columnDefs”: [ { “type”: “formatted-num”, “targets”: [ 0 ] } ]

    Other tables work properly if I have the number separated out into its own column (as seen on https://fitsmallbusiness.com/best-states-to-start-a-business/) but I would really love to not have to do that. Can you please lend a hand?

    Thanks in advance!!

    The page I need help with: [log in to see the link]

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    thanks for your question, and sorry for the trouble.

    The cause for that simply is that the first column is more than just plain numbers. The sorting algorithm therefore can’t know how to treat this.

    The “Custom Command” that you found is the perfect solution though, and I recommend that you use that. To make it work, you will however first have to download, install, and activate the TablePress Extension from https://tablepress.org/extensions/datatables-sorting-plugins/

    Regards,
    Tobias

    Thread Starter cbottorff89

    (@cbottorff89)

    Hi Tobias,

    We do have the extension, I just don’t know how to adjust the code.

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    the command that you mentioned above is correct. Just add

    "columnDefs": [ { "type": "formatted-num", "targets": [ 0 ] } ]
    

    to the “Custom Commands” textfield on the table’s “Edit” screen.

    Regards,
    Tobias

    Thread Starter cbottorff89

    (@cbottorff89)

    Hi Tobias,

    The code is in that field but doesn’t work; that’s why I thought I needed to adjust it. Any other ideas?

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    when I check the source code of the page https://fitsmallbusiness.com/best-states-for-women-entrepreneurs/, I don’t see the code added there. Also, I don’t see that the Extension’s JS file is loaded. Are you sure that you added it to the “Custom Commands” field of the table that is shown on that page?
    Did you clear the cache?

    Regards,
    Tobias

    Thread Starter cbottorff89

    (@cbottorff89)

    Hi Tobias,

    I wish I could upload a screenshot but yes I’m fairly sure I put it in the right location. At the bottom of the page is a box that says “Features of the DataTables JavaScript Library.” The “Use DataTables” box is checked and so is the one for “Sorting.” Then I put the code in the “Custom Commands” field at the bottom.

    I tried clearing the cache and a different browser but it still doesn’t list items sequentially. How would I check if a JS file is loaded (does that mean JavaScript)?

    (I apologize, you’re speaking to someone with very little coding experience.)

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    indeed, now I can see the “Custom Command” in the page’s source code.
    I don’t see the necessary JS file though. Are you sure that you downloaded and installed the TablePress Extension from https://tablepress.org/extensions/datatables-sorting-plugins/ as a new WordPress plugin?

    Regards,
    Tobias

    Thread Starter cbottorff89

    (@cbottorff89)

    Hey there,

    The plugins on our site are managed by another department, so I’ve sent them a link to this conversation and will let them investigate. Thanks.

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    sounds good! Without this plugin, the code above will not work.

    Regards,
    Tobias

    Thread Starter cbottorff89

    (@cbottorff89)

    I think we’ve finally got this sorted out. Thank you for the assist!

    Plugin Author Tobias Bäthge

    (@tobiasbg)

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

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

The topic ‘Table will not sort sequentially’ is closed to new replies.