I'm trying to implement a click function on a specific column but it's only working for the first row.
My table is dynamic and the content is based on stream from web sockets.
Here is what I'm trying to do:
function initTable($table) {
window.dataTable = dataTable = $table.DataTable({
data: workerObjects,
columns: [
{ title: "Agent", data: "friendlyName" },
{ title: "Listen",
render: function(data, type, row) {
if ( !row.task ) { return '-' }
return `<a href='#' id="join_${row.task.sid}"><i id="${row.task.sid}" class="fa fa-play-circle"></i></a>`
}
},
],
pageLength: 25
});
// https://github.com/benjamine/jLiveTime
$table.livetime();
$table.on('click', 'td:eq(1)', function (event) {
console.log('bang';
});
return dataTable;
}
In a specific flow, I run dataTable.rows().invalidate().draw(); to update table because object workerObjects has been updated.
How can i make $table.on('click', 'td:eq(1)'... works for every row? Right now, it's only working for first row.
$table.on('click', 'td'..., because'td:eq(1)'means only for the firsttd