{hero}

DataTable.type()

Since: DataTables 2.0

Get / set details of a data type.

Description

DataTables operates on the data shown in the table in a number of different ways depending on the structure of the data. We term each unique structure as a data type. For example, numbers, HTML data, dates, etc.

This method provides a method to get a list of the data types that have been registered with DataTables. Its companion method DataTable.type() can be used to obtain details about and set options for each data type.

For more details about the data type system in DataTables please refer to the documentation on DataTables.net.

Types

function type( name )

Description:

Get an array of the data types that have been registered with DataTables.

Parameters:
Returns:

Object with details of the data type's processing.

function type( name, definition )

Description:

Set a definition for data type. Will create a new one if the name doesn't yet exist, or will merge with an existing one if it already does.

Parameters:
Returns:

No return value.

function type( name, property, definition )

Description:

Set a specific property of a data type, allowing fine grade control and tuning of data types.

Parameters:
Returns:

No return value.

Examples

Get the information about the num data type:

let numberType = DataTable.type('num');

console.log(numberType.className);

Remove the default right alignment of number data types:

DataTable.type('num', 'className', '');

Create a new data type (in this case type detection, ordering and a class for IPv4 addresses):

DataTable.type('ipv4', {
	detect: function (data) {
		return typeof data === 'string' &&
			data.match(/^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/)
				? 'ipv4'
				: null;
	},
	order: {
		pre: function (data) {
			return Number(
				data
					.split('.')
					.map((num, idx) => num * Math.pow(2, (3 - idx) * 8))
					.reduce((a, v) => ((a += v), a), 0)
			);
		}
	},
	className: 'dt-data-ipv4'
});

Related

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