columnOrder

Since: Buttons 4.0.0

A button that will control the ordering on a single column.
Please note - this property requires the Buttons extension for DataTables.

Description

Buttons created by extending this button type will have the ability to control the ordering of a column - i.e. when activated the table will order by the target column.

The behaviour of the button will depend on the state of the table:

  • If already ordering by the target column, the ordering will be inverted.
  • If not year ordering by the target column, the first ordering in columns.orderSequence will be used.

In both cases the order will immediately be applied and the table redrawn.

Additionally, this button type makes use of split buttons to allow a tidy UI to be displayed to the end user, while still giving them full control. In this case, the sub-buttons will give the end user the ability to specify which direction of ordering should be applied. If columns.orderSequence is used to restrict the ordering to a specific direction, the split buttons will not be shown.

Options

This button can have the following options set in its configuration object to customise its actions and display, in addition to those options which are available for all buttons (e.g. buttons.buttons.text):

className

  • Type: string
  • Default: buttons-collection buttons-column-order

The button's class name. See buttons.buttons.className for details.

column

A selector for the column that will be managed by this button. You can use a column index, or a selector, as defined by the column selector option. Only a single column should be selected.

text

The button's display text. By default the button title will match the title of the target column. Please note, that for the sub-buttons, if you wish to translate the ascending and descending phrases, please use buttons.order.asc and buttons.order.desc, respectively, in the DataTables language object.

Example

Show the columnOrder button:

new DataTable('#myTable', {
	layout: {
		topStart: {
			buttons: [
				{
					extend: 'columnOrder',
					text: 'Order by Position',
					column: 1
				}
			]
		}
	}
});