getting specific data of selected row
getting specific data of selected row
Hi everyone,
I'm desperately trying to get specific data from the selected rows.
I want to get the data-ID attribute of the second column of each selected rows, but I only have access to the content of the cell.
<tr>
<th>Customer name</th>
<th>City</th>
<th>Amount</th>
</tr>
<tr id="1234">
<td data-id="553">Jason</td>
<td>Paris</td>
<td>$140</td>
</tr>
<tr id="1255">
<td data-id="704">Mike</td>
<td>London</td>
<td>$114</td>
</tr>
var rows = table.rows({selected: true} ).data().toArray();
for (let i in rows) {
console.log(JSON.stringify( rows[i][1] )); //shows Jason
}
Any help please ?
This question has an accepted answers - jump to answer
Answers
You will need to use
rows().nodes()
to get thetr
nodes for the row. Better is to usecells().nodes()
. See this examplehttp://live.datatables.net/feqekoje/1/edit
It uses
rows().indexes()
to get the indexes of the selected rows. The indexes are used for the rows parameter ofcells().nodes()
.to$()
is used to return a jQuery object. The loop is used to get theid
of eachtd
in the array.Kevin
perfect kthorngren,thank you genius
But can I also get the td content ?
I'm trying :
but it doesn't work....
UPDATE
It's okay. I just had to use
Thanks again
You can also use
cells().data()
orcell().data()
to get the data of the cell.Kevin