JQuery datatable sort by column header

Basically, jQuery Datatable allows you to sort data by column index.

"order": [1, 'desc']

I wonder if we can sort by column heading name? For instance:

"order": ['my_column_name', 'desc']

Thankyou alex

+4
source share
1 answer

Is there a way to use the name, data, or column class to set the default sorting of columns? No - not at this time.

Although this thread was published in June-2015, but still I could not find such functionality in the latest version of DataTable.

Like a note! You must provide a column indexDataTable when ordering data, but you can get Column Nameone that uses ordering.

var order = table.order();
var columnIndex = order[0][0]; //column index
var orderDirection =order[0][1]; // asc or desc

//Get column header text;
var title = table.column(order[0][0]).header();
var columnName = $(title).html(); //Column Name

+2
source

Source: https://habr.com/ru/post/1674940/


All Articles