1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
<?xml version="1.0" encoding="UTF-8" ?>
<dt-option group="option">
<name>rowId</name>
<summary>Data property name that DataTables will use to set `-tag tr` element DOM IDs</summary>
<since>1.10.8</since>
<type type="string" />
<default value="DT_RowId" />
<description>
It can often be useful to have a [`id` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id) on each `-tag 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 `dt-init 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](http://www.w3.org/TR/html5/dom.html#the-id-attribute) 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](http://www.w3.org/TR/CSS21/syndata.html#value-def-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.
</description>
<example title="Use the property `staffId` as the data source for the row id"><![CDATA[
$('#myTable').DataTable( {
ajax: '/api/staff',
rowId: 'staffId'
} );
]]></example>
<related>dt-init rowId</related>
<related>dt-api row().id()</related>
<related>dt-api rows().ids()</related>
</dt-option>
|