columns().orderable()
Get information about the orderable status of the selected columns.
Description
This method provides the ability to programmatically check if the given columns are orderable by the end user (a click on the header cell) and optionally to get the ordering directions that the column can take, as defined by columns.orderSequence
.
Type
function columns().order( [ directions ] )
- Description:
Get information about the orderable status of the selected columns (enabled or not and what ordering directions are available).
- Parameters:
Name Type Optional 1 directions
Yes - default:false Controls the information that is returned - see below for details. Can be not given (undefined),
false
ortrue
.- Returns:
DataTables API instance containing
true
orfalse
for each selected column, depending on the orderable state and ifdirections
is undefined or false. If the parameter passed in istrue
the method will return information about what ordering directions the columns can take (seecolumns.orderSequence
).
Example
Check if the first and second columns are orderable by the end user, and if so, order on them:
var table = new DataTable('#myTable');
if (
table
.columns([0, 1])
.orderable()
.includes(true)
) {
table
.order([
[0, 'asc'],
[1, 'desc']
])
.draw();
}
Related
The following options are directly related and may also be useful in your application development.