rowId

Since: DataTables 1.10.8

Data property name that DataTables will use to set tr element DOM IDs.

Description

It can often be useful to have a id attribute on each tr element in a DataTable for row selection and data source identification, particularly when using events.

DataTables will attempt to automatically read an id value from the data source for each row using the property defined by this option. By default it is DT_RowId but can be set to any other name. As with columns.data it can also read from a nested JSON data source by using Javascript dotted object notation (e.g. DT_RowId: 'image.id').

If no id value for the row is found, the id property will not be automatically set.

Any row id values that are given in the data source should match the HTML specification for what values it can take:

The value must be unique amongst all the IDs in the element's home subtree and must contain at least one character. The value must not contain any space characters.

You may also wish to consider the CSS 2.1 specification of an identifier which is more restrictive than HTML5's and will provide maximum compatibility with jQuery:

identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, two hyphens, or a hyphen followed by a digit. Identifiers can also contain escaped characters and any ISO 10646 character as a numeric code.

Type

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

Default

  • Value: DT_RowId

Example

Use the property staffId as the data source for the row id:

$('#myTable').DataTable( {
	ajax: '/api/staff',
	rowId: 'staffId'
} );

Related

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