1

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">&nbsp;&nbsp;&nbsp;</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?

2
  • 3
    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).” Commented Apr 10, 2019 at 8:56
  • 1
    thanks mate! I overlooked that. if you submit your reply as answer I accept it Commented Apr 10, 2019 at 9:03

1 Answer 1

2

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”.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.