• Resolved rlaflamme

    (@rlaflamme)


    Hi there,

    First of all, I want to say what a fantastic plugin this is. I’ve been tinkering with it for a few days now, and between the inherent functionality and a few older threads, I managed to get it to sort in a number of the ways I want.

    The last hurdle I have pertains to sorting one particular column. The title of the column we’ll call “Rankings”, with all of the subsequent rows having numbers that would correspond to say, tracking team scores. There are entries like ‘5-3’, ‘2-8′, 1-4’, and so on.

    What would be the best suggested means of having this column sort in a numeric way so that it would be shown in a sequential ascending / descending listing? (For example, 1-4, 1-5, 1-6, 2-4, 2-5, etc). I thought about the num-html plugin but my first attempt at that didn’t seem to work.

    Thanks again!

    https://wordpress.org/plugins/tablepress/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    I can see what you are trying to do here, but unfortunately, this is not something that the sorting can take care of automatically. The existing algorithms basically can not know how a cell content like 1-5 should be treated. You would therefore need to implement a custom sorting algorithm for this (similar to the algorithms that are available in this TablePress Extension: http://tablepress.org/extensions/datatables-sorting-plugins/ )
    Another solution would be to manually sort those rows in a hidden column, which is explained (in a similar way) here: http://wordpress.org/support/topic/substitute-word-for-numbers-for-sorting-issues?replies=6

    Regards,
    Tobias

    Thread Starter rlaflamme

    (@rlaflamme)

    Hi Tobias,

    Sorry for the lengthy break there. Time to test this and all.

    I went ahead and did the custom hidden field, and that seems to be working just fine for that portion of it.

    I did run into one odd behavior when arranging by the alt-string columns that I think has to do with the custom field. I currently have for a custom command:

    "aoColumnDefs": [ { "sType": "alt-string", "aTargets": [ 3,4,5,6,7,8 ] } , {"asSorting": [ "asc", "desc" ], "aTargets": [ 0,1 ]} , { "bVisible": false, "aTargets": [ 2 ] }, { "iDataSort": 2, "aTargets": [ 1 ] } ]

    Of the visible fields, Column 1 is just normal text, and Column 2 is numbers being sorted by the invisible column. Both of these sort ascending or descending when clicking on the header just fine.

    Columns 3-8 also work when sorting by the alt-string criteria, which are also just text being sorted alphabetically in a binary way (e.g. ‘Red’ or ‘Green’). It wasn’t arranging those rows alphabetically secondarily according to Column 1 though until I added the “asSorting” field. By itself, that seemed to work.

    However, I have noticed that if I were to, say, sort Column 1 or 2 and leave the list in the descending order (Z-A), then try to sort by one of the alt-sting columns, it sorts them according to the alt-string criteria, but doesn’t arrange them in an alphabetical order.

    It only seems to happen in the corner case of clicking twice to sort by descending order for Columns 1 or 2 and then trying to sort by alt-string. However, I’m not sure how I’d correct this last part.

    Thanks again!

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    ok, that sounds complicated.
    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!

    I’m not that much of an expert with the internals of the DataTables JS library, as I’m not its developer, but I might be able to spot something that could be causing this.

    Regards,
    Tobias

    Thread Starter rlaflamme

    (@rlaflamme)

    Sure thing. I’m not sure if it’s an error per se or if I just need further command clarification (like some sort of multi-field sorting).

    Please note that this page is not yet live, but I have made it password protected so you can look at it. The PW is ‘Oranges123’ for you to look. The link is: http://bit.ly/1qzFXnC

    Thanks!

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for the link. That’s indeed a little bit strange, and I don’t see why this is necessary. I guess, if you really wanted to solve this mystery, you could ask the DataTables developer. 🙁

    Best wishes,
    Tobias

    Thread Starter rlaflamme

    (@rlaflamme)

    I thought as much. Any place you could direct me to?

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    the best chance is probably in the DataTables forums at http://www.datatables.net/

    Regards,
    Tobias

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Suggestion for numeric sorting’ is closed to new replies.