Disable Header Sort Event

Disable Header Sort Event

jimboyjimboy Posts: 20Questions: 9Answers: 0

Hi,

How do disable the headers click sorting event? Below doesn't work.

function InitDataTable() {
var $this = $('#table');

        $this.dataTable({
            dom: 'frltip'
            initComplete: function (settings, json) {
                $(this).unbind('click.sorting'); //not working
                $(this).find("th").off("click.DT"); //not working
            }
        })

        $this.unbind('click.sorting'); //also not working outside initComplete
        $this.find("th").off("click.DT"); //also not working outside initComplete

    console.log('init_datatable');

}

Thanks,

This question has an accepted answers - jump to answer

Answers

  • TooManyTablesTooManyTables Posts: 23Questions: 7Answers: 1
    edited September 2017 Answer ✓

    What's the objective? Are you trying to turn off sorting on all of the columns in your table? If that's the case, then you can do the following (from this page) when intialising your table:

    $this.dataTable({
        dom: 'frltip',
        orderable: false
     })
    

    If that's not what you're after, you'll probably have to give a little bit more background information.

  • jimboyjimboy Posts: 20Questions: 9Answers: 0

    Hi TooManyTables,

    Yes, I'm trying to turn off all the columns sorting and removing the sort icon.

    Below code works,

               order: false,
                columnDefs: [{
                    targets: "_all",
                    orderable: false
                }],
    
  • Jeff AJeff A Posts: 50Questions: 8Answers: 0

    Just what I was looking for too.

This discussion has been closed.