{hero}

columns.orderData

Since: DataTables 1.10

Define multiple column ordering as the default order for a column.

Description

Allows a column's sorting to take either the data from a different column as the data to sort, or data from multiple columns.

A common example of this is a table which contains first and last name columns next to each other, it is intuitive that they would be linked together to multi-column sort.

Another example is the case where the data shown to the end user is not directly sortable itself (e.g. a column with images in it), but there is some meta data than can be sorted (e.g. a file name) which is present in a different (perhaps hidden) column. This option can be used to instruct DataTables to order the image column based on the hidden column's data. It is worth noting that if you do this, you will likely want to include the visible column in the orderData array, so the ordering indicator at the top of the column shows the ordering that is applied to the end user. Furthermore, orthogonal data is an alternative method that can be used for separating display and ordering data.

Types

integer

A single column index to order upon

array

Multiple column indexes to define multi-column sorting

Default

Takes the index value of the column automatically

Examples

Using orderData to define multi-column sorting with columnDefs:

new DataTable('#myTable', {
	columnDefs: [
		{ orderData: [0, 1], targets: 0 },
		{ orderData: 0, targets: 1 },
		{ orderData: [2, 3, 4], targets: 2 }
	]
});

Using orderData to define multi-column sorting with columns:

new DataTable('#myTable', {
	columns: [
		{ orderData: [0, 1] },
		{ orderData: 0 },
		{ orderData: [2, 3, 4] },
		null,
		null
	]
});

Related

The following options are directly related and may also be useful in your application development.