anderish
anderish

Reputation: 1759

DataTable Initial Sort Only

I have a table and I want to display the table with column 1 ordered asc.

$("#table").DataTable({
    "order": [[ 0, "asc" ]],
});

This works great, however, I would like to turn off the sorting mechanism after this initial order.

$("#table").DataTable({
    "order": [[ 0, "asc" ]],
    "ordering": false
});

But this removes the inital sorting mechanism as well. Any ideas?

Upvotes: 0

Views: 34

Answers (2)

Özcan Esen
Özcan Esen

Reputation: 340

You can remove click event listeners from table header, so when user clicks nothing will happen.

$('#table th').unbind().css('cursor', 'auto');

Upvotes: 1

Sammy Ellis
Sammy Ellis

Reputation: 69

Usually when I face this situation I simply sort the DataTable data first, then create the DataTable. Depending on how you are retrieving the data you can do this pretty easily, (ie. SQL with SORT or ORDER BY statements, etc.)

Upvotes: 0

Related Questions