Globally set an orderable trait on a class

Globally set an orderable trait on a class

DanBridgemanDanBridgeman Posts: 3Questions: 1Answers: 0
edited October 2018 in Free community support

I see how I can set columns with a class of 'no-sort', and then use columnDefs to make those columns not orderable when intializing each DataTable.

$('#example').DataTable({
    columnDefs: [{ orderable: false, targets: 'no-sort' }],
});

But it would be much easier if I didn't have to set this on every DataTable. Is there something I could do globally to set any column with a 'no-sort' class not to be orderable by default?

This question has an accepted answers - jump to answer

Answers

  • DanBridgemanDanBridgeman Posts: 3Questions: 1Answers: 0
    edited October 2018

    Had to edit that....

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Hi @DanBridgeman ,

    Yep, you can easily tweak the defaults before initialising the table, something like this.

    Cheers,

    Colin

  • DanBridgemanDanBridgeman Posts: 3Questions: 1Answers: 0

    I took the portion that extends the DataTable defaults, and put that into a shared JavaScript file, and it works perfectly.

    $(document).ready(function () {
        $.extend(true, $.fn.dataTable.defaults, {
            'columnDefs': [{ orderable: false, targets: 'dt-nosort' }]
        });
    });
    

    Many thanks @colin!

This discussion has been closed.