{hero}

order

Since: DataTables 1.10

Initial order (sort) to apply to the table.

Description

If ordering is enabled (ordering), then DataTables will perform a first pass order during initialisation. Using this parameter you can define which column(s) the order is performed upon, and the ordering direction. The order can be defined in a number of different ways as defined by DataTables.Order.

Type

This option can be given in the following type(s):

Default

  • Value: [[0, 'asc']]

Examples

No ordering applied by DataTables during initialisation. The rows are shown in the order they are read by DataTables (i.e. the original order from the DOM if DOM sourced, or the array of data if Ajax / data sourced):

new DataTable('#myTable', {
	order: []
});

Multi-column ordering as the initial state (using tuples):

new DataTable('#myTable', {
	order: [
		[0, 'asc'],
		[1, 'asc']
	]
});

Single-column ordering as the initial state (using objects):

new DataTable('#myTable', {
	order: {
		idx: 1,
		dir: 'asc'
	}
});

Single-column ordering as the initial state (using objects and column names):

new DataTable('#myTable', {
	columns: [
		{ name: 'first_name' },
		{ name: 'last_name' },
		{ name: 'position' },
		{ name: 'city' }
	],
	order: {
		name: 'city',
		dir: 'asc'
	}
});

Related

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