rowId from event driven table
rowId from event driven table
tisawyer
Posts: 12Questions: 4Answers: 1
in DataTables
I'm attempting to add a rowId like so:
var t = $('#mlh').DataTable( {
rowId: 'rKey'
});
from data generated this way:
es.addEventListener('lastheard', function (event) {
var tableData = JSON.parse(event.data).data;
console.log(tableData.length);
if (typeof tableData !== "undefined") {
i=0;
// Handle one or more rows
for (i=0; i < tableData.length; i++) {
console.log(tableData[i]);
t.row.add([
tableData[i].rKey,
tableData[i].timeStamp,
tableData[i].duration,
tableData[i].source,
tableData[i].user,
tableData[i].talkGroup,
tableData[i].rssi,
tableData[i].cBridge,
tableData[i].pktLoss,
tableData[i].sourceNo,
tableData[i].userNo
]).draw(false);
}
}
});
Tried various variations of above but no luck. TIA for helping.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Why not use this?
https://datatables.net/reference/option/createdRow
Inside the function you provide, $(row).attr('id', data.rKey)
You could also check out this.
https://datatables.net/reference/option/rowCallback
But the documentation does say,
"This function might be used for setting the row class name or otherwise manipulating the row's TR element (although note that `dt-init createdRow can often be more efficient)."
The data var is an array here. This did the trick.
Thank you!