• Resolved alinford

    (@alinford)


    I have downloaded DataTables hoping that would work, but it does not.
    I have a column that has Heights in it (feet’inches”).
    Looks like this:
    5’10”
    5’6″
    5’11”
    6’2″
    5’7″
    etc…

    In the admin area, the heights sort correctly, but they do not on the actual page. Any ideas?

    https://www.ads-software.com/plugins/tablepress/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    Unfortunately, I’ll have to disappoint you here. TablePress does not ship with a sorting algorithm for heights like that, and as far as I know, DataTables does also not offer one at the moment.
    The reason why it works on the “Edit” screen is pretty much luck, in that the sorting library on the “Edit” screen interprets the strings differently and uses “natural” sorting.

    So, in order to get these to sort correctly, you could develop a custom sorting algorithm using the DataTables API functions.
    Another idea would be to tell DataTables to not actually use this data for the sorting, but that from an extra (but invisible to the user) column. That means, you could add a new column to the table, where you manually enter the height values in inches, as a plain number. Then, you could use a “Custom Command” on the table’s “Edit” screen like

    "columnDefs": [ { "visible": false, "targets": [ 3 ] }, { "orderData": [ 3 ], "targets": [ 2 ] } ]

    to tell DataTables to hide that new column, and to use the data from that hidden column for the sorting of the actual heights column.
    (The numbers here would have to be adjusted: The “2” would refer to the actual height column (where 2 indicates third column, as counting in this code starts with 0). The “3” would refer to the hidden column (where 3 indicates fourth column).

    Regards,
    Tobias

    Thread Starter alinford

    (@alinford)

    That is what I thought. Thanks for the help.
    I ended up using 3 digits for each height in the hidden columns to make it simple:
    Col 5 = Col 6
    5’10” = 510
    5’6″ = 506
    5’11” = 511
    6’2″ = 602
    5’7″ = 507
    etc…

    I was already using a hidden column to sort by grade:
    Col 2 = Col 3
    Freshman = 09
    Sophomore = 10
    Junior = 11
    Senior = 12

    So, my sort used an array:
    "columnDefs": [ { "visible": false, "targets": [ 3,6 ] }, { "orderData": [ 3], "targets": [ 2] }, { "orderData": [ 6 ], "targets": [5] }]

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    yes, that’s what I meant! ?? Good to hear that this workaround worked for a second time already! ??

    Best wishes,
    Tobias

    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Sort by Height?’ is closed to new replies.