• Recently created a new site with a tablepress table but it doesn’t seem to be sorting the columns properly. Number sequence of 1.1, 15.45, 9, and 3 is being sorted like 1.1 – 15.45 – 3 – 9. Any ideas what might be causing this? I did a search but wasn’t able to find something specific for this.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi,

    thanks for your post, and sorry for the trouble.

    This happens if not all cells in that column are numbers. The DataTables JS library that does the sorting, will then sort the column as strings, which are sorted differently than numbers.
    So, please check if really all cells in that column are numbers.

    If that still doesn’t help, please post a link to the page with the table, and I’ll take a direct look.

    Regards,
    Tobias

    Thread Starter Edeezy

    (@edeezy)

    Thanks for the super quick response :). Well all of the numbers in the column are numbers, though they are in decimal format so this may be the cause? The funny thing is it sorts correctly in the wordpress backend of the site but not on the live page.

    The url is https://www.bestledflashlightsguide.com.
    As it currently stands, only one of the columns is sorting correctly and thats the rating column.

    Thanks again for taking the time to respond to this.

    Ed

    Hi Ed,

    thanks for the link!

    Yes, the numbers are all numbers (decimals with a . are no problem). However, there’s some white space in several of the table cells (like spaces pr line breaks after the last digit), and those unfortunately cause this trouble in the external JavaScript library that is used for the sorting.
    So, on the “Edit” screen of the table, please go through each cell in the columns that are not sorting correctly, and remove all trailing white space from the cells. That should fix the issue.

    Regards,
    Tobias

    Thread Starter Edeezy

    (@edeezy)

    Hi Tobias,

    Thanks for taking a look at it, this was able to sort the issue for the columns with numbers so that’s great :). There’s one more issue though, the price column with the $ characters is not sorting for some reason. I changed it to * and it began to work perfectly.
    Any idea why this is happening? Perhaps I need an additional extension?

    Thanks again for taking the time to look at this, really appreciate it.

    Ed

    Hi Ed,

    good to hear that this helped solving the sorting! ??

    About the column with the $: The problem here is, that the plugin can’t know that you suddenly want to sort on the number/count of $ characters in the cell. Thus, the sorting is not as expected.
    I therefore recommend a small work around: You should add a new column directly next to the column with the $, and put in the count of $ characters for that row. Then, we can tell the JS library to use that value for sorting, and we can hide it.

    Please add this to the “Custom Commands” textfield on the “Edit” screen of the table:

    "aoColumnDefs": [ { "iDataSort": 5, "aTargets": [ 4 ] }, { "bVisible": false, "aTargets": [ 5 ] } ]

    That code assumes that the new column is the sixth column in the table then (counting starts with 0, that’s why the 5 and 4 in the code).

    Regards,
    Tobias

    Thread Starter Edeezy

    (@edeezy)

    Hi Tobias,

    I’m currently trying to implement the workaround that you suggested. I’ve added the column as you said but I’m a bit unsure on the next part of the instructions. When you say put in the cout of $ characters for that row, do you mean like for example “row 2 price of $$$$” should the entry in the new column’s row be 4 or $$$$ as well? Should this be done for every row?

    I hope that’s not too confusing ??

    Ed

    Hi,

    the value in the new column should be a number. “4” if there’s $$$$ in the price column of that row, 3 if there’s $$$ in the price column, and so on. Just the number/count of $ characters in the Price column of that row, and that for every row.
    With that, the sorting script can use the number to do the sort on (as it does understand numbers, but not symbols like $).

    Regards,
    Tobias

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Tablepress Not Sorting columns correctly?’ is closed to new replies.