WordPress.org

Ready to get started?Download WordPress

Forums

TablePress
[resolved] Sorting - only specific columns? (14 posts)

  1. Quest The Wordsmith
    Member
    Posted 1 year ago #

    I have a table with a few columns. When I turn the sorting feature on, it enables sorting on every column. Is there a way to just enable it for specific columns? Thanks.

    http://wordpress.org/extend/plugins/tablepress/

  2. Quest The Wordsmith
    Member
    Posted 1 year ago #

    I found this in the forums: http://wordpress.org/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.

  3. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    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 http://datatables.net/usage/columns

    Regards,
    Tobias

  4. Quest The Wordsmith
    Member
    Posted 1 year ago #

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

  5. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    thanks for the nice words :-) That's great to hear!
    Donations are possible at http://tablepress.org/donate/ Thanks!

    Best wishes,
    Tobias

  6. Quest The Wordsmith
    Member
    Posted 1 year ago #

    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 ] } ]'

  7. Quest The Wordsmith
    Member
    Posted 1 year ago #

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

  8. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    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

  9. Quest The Wordsmith
    Member
    Posted 1 year ago #

    Perfect! thank you.

  10. TobiasBg
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    sure, no problem! You are very welcome!

    Best wishes,
    Tobias

  11. OnCrypto
    Member
    Posted 5 months ago #

    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.

  12. TobiasBg
    Member
    Plugin Author

    Posted 5 months ago #

    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

  13. OnCrypto
    Member
    Posted 5 months ago #

    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.

  14. TobiasBg
    Member
    Plugin Author

    Posted 5 months ago #

    Hi Paul,

    no problem! :-) Good to hear that it's working now!

    Best wishes,
    Tobias

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic