This topic contains 3 replies, has 2 voices, and was last updated by Sean Sean 2 years, 9 months ago.

Datatables: How to enable sorting and disable sorting on columns?????

  • vernard
    vernard
    Participant

    Posts: 1
    Member Reply #5053

    This is probably a simple thing to do but may require editing a JS file… but I’m not sure, so I’ll just ask first,

    On the datatables, by default the first column has the checkboxes and the rest of the columns have column headers that have the “sorting” arrows.

    When I tried to assign the checkboxes to the last column, I get a column that has a sort icon and the first column called “username” doesn’t sort.

    So I realised, anything that cannot be sorted or is a row management “thing” has to be in the first column… which is problematic because I want the checkboxes on the right-most, not on the left-most.

    How do I disable sorting and enable sorting for certain columns?

    Attachments:
    You must be logged in to view attached files.
    Sean
    Sean
    Keymaster

    Posts: 4527
    Support Staff Reply #5093

    Hi :),

    You can use below parameter in your datatable setup:

    “columnDefs”: [ {

    “targets”: [0, 1, 2], // column or columns numbers

    “orderable”: false,  // set orderable for selected columns

    }],

    For more info please check http://datatables.net/reference/option/columnDefs

    Thanks.

    vernard
    vernard
    Participant

    Posts: 1
    Member Reply #5111

    Thanks! That works!

    I consulted datatables.net first but I actually added the JS script in the HTML file itself, so it didn’t work.  It wasn’t clear that to edit stuff in the datatable one should look at assets > pages > scripts file.

    Sean
    Sean
    Keymaster

    Posts: 4527
    Support Staff Reply #5131

    Great! Good luck with your project 🙂

You must be logged in to reply to this topic.