Reputation: 2048
In my datatable I set the ID attribute for rows:
'createdRow': function (row, data, dataIndex) {
$(row).attr('id', data.json.unid);
}
Under a button I want to grab the ID's:
action: function () {
var count = table
.rows({
selected: true
})
.ids();
alert("id:s" + count)
for (i = 0; i < count.length; i++) {
alert("id:" + count[i])
}
rpcService
.setIds(count
.toArray());
}
In the alert I get for the ID "undefined".
Here is what a row looks like:
<tr id="FF97C3CFC0F5FA76C12583D1003EA028" role="row" class="odd selected">
<td class=" select-checkbox"> </td>
<td><a href="0/FF97C3CFC0F5FA76C12583D1003EA028?OpenDocument">Anne Weinstein</a></td>
<td>ORP B</td>
<td><a href="0/FF97C3CFC0F5FA76C12583D1003EA028?OpenDocument">Anne Weinstein</a></td>
<td>s41660</td>
</tr>
What am I doing wrong?
Upvotes: 1
Views: 866
Reputation: 5820
You are setting IDs on the elements in the DOM, but the .ids()
method is not supposed to return those.
https://datatables.net/reference/api/rows().ids()
Important This method does not read the DOM id for the tr elements, but rather gets the row id from the row's data source (location specified by rowId).
You would need to provide the IDs upfront in your data source already, so that you can match them via the rowId
option, to get what datatables considers a “row id”.
Upvotes: 2