Viewing 13 replies - 1 through 13 (of 13 total)
  • Thread Starter Quest The Wordsmith

    (@quest-the-wordsmith)

    I found this in the forums: https://www.ads-software.com/support/topic/deactivate-sorting-for-a-specific-columns?replies=4

    Where would I implement this javascript? And is there a list of these variables that are able to be tweaked? I’m looking to enable sorting only for the first 2 columns. Thanks.

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    thanks for the question.

    Yes, you can turn off sorting on certain columns with a “Custom Command” for the DataTables JavaScript library (which TablePress uses for the sorting feature).

    For example, paste

    "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 0, 1, 4 ] } ]

    This would turn off sorting for columns 1, 2, and 5. (The counting of the numbers in the code starts with 0.)

    Update: Just saw your reply. This code needs to go into the “Custom Commands” text field in the “Features of the DataTables JavaScript library” section on the “Edit” screen of the table. To deactivate sorting on the first two columns, you would use the value [ 0, 1 ] in the code from above. For a list of available variables/modifies, please take a look at the DataTables documentation at https://datatables.net/usage/columns

    Regards,
    Tobias

    Thread Starter Quest The Wordsmith

    (@quest-the-wordsmith)

    Dude, you seriously have to be the most responsive author in all of WordPress land. Hats off to you. Where can I donate?

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    thanks for the nice words ?? That’s great to hear!
    Donations are possible at https://tablepress.org/donate/ Thanks!

    Best wishes,
    Tobias

    Thread Starter Quest The Wordsmith

    (@quest-the-wordsmith)

    I have this code above combined with another code. Not that I put both of them in the custom commands box, the first one (the one on this page) is not working. I switched them around, and the same thing happens with whatever is first. Here’s exactly what I have in my command box:

    '"aoColumnDefs": [ { "bSortable": false, "aTargets": [ 2, 3, 4 ] } ], "aoColumnDefs": [ { "bSearchable": false, "aTargets": [ 2, 3, 4 ] } ]'

    Thread Starter Quest The Wordsmith

    (@quest-the-wordsmith)

    The above doesn’t actually have the ‘ before and after, that was me trying to use the code tag properly here in the forum.

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    to combine these two commands, you’ll have to combine them inside the "aoColumnDefs", like this:

    "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 2, 3, 4 ] }, { "bSearchable": false, "aTargets": [ 2, 3, 4 ] } ]

    Regards,
    Tobias

    Thread Starter Quest The Wordsmith

    (@quest-the-wordsmith)

    Perfect! thank you.

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    sure, no problem! You are very welcome!

    Best wishes,
    Tobias

    Hi Tobias,

    is there a way to specify certain columns in certain table id-s to be non-sortable. ie, I understand the above posts and solutions, but wish to apply them to certain columns within 1 or 2 tables only, within my collection of many tables.

    Warm regards,
    Paul.

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi Paul,

    thanks for your question.

    Then that solution from above is perfect, as it only applies to one table at a time.
    Just paste something like

    "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 2, 3, 4 ] } ]

    into a table’s “Custom Commands” field on the table’s “Edit” screen to turn of sorting for certain columns (columns 3, 4, and 5 in that example, as counting in the code starts with 0).

    Regards,
    Tobias

    Oh ok, thanks for that, I misread the previous posts as saying that the code went into the general coding for the back-end of the plugin (ie the files themselves). I’ve found the custom commands section now, sorry for taking up your time, I should have triple checked before posting!

    You are the best Tobias,
    Warm regards,
    Paul.

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi Paul,

    no problem! ?? Good to hear that it’s working now!

    Best wishes,
    Tobias

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Sorting – only specific columns?’ is closed to new replies.