DataTable.type()
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:
Name Type Optional 1 name
No The name of the data type for which information should be obtained.
- 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:
Name Type Optional 1 name
No The name of the data type for which the definition is to be set.
2 definition
No The type information object to be set. Each property is optional and if the data type already exists, if it property is not set here, it will not remove a previous value.
- 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:
Name Type Optional 1 name
No The name of the data type for which the definition is to be set.
2 property
No The property of the data type to be set. This can be one of any of the top level property names in
DataTable.Type
- e.g.className
,detect
,order
,render
orsearch
.3 definition
Any
No The type information object to be set.
- 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.