row clickevent selects wrong row
row clickevent selects wrong row
Hi,
I'm kind of new to javascript and jQuery, but I need to develop an interactive table which is sourced from the DOM. I am trying to create an event when a row is clicked is the generated table. However, when I click any row, the row selected is always the first row. Any thoughts how to fix this? The table is generated by the HTML twig framework and I am using the latest version of DataTables and jQuery.
Code snippet below
`` var projecttable = $('#projectTable').DataTable({
"dom":'rtp',
"paging": false,
"columnDefs":[{
"targets": [3],
"searchable": false,
"orderable": false,
"visible": true,
},{
"targets": [1],
"searchable": true,
"orderable": false,
"visible": false,
}],
"order":[[1,'asc']],
});
$('#projectTable').on('click', 'tr', function () {
if($(this).hasClass('selected') ) {
$(this).removeClass('selected');
}else{
projecttable.$('tr.selected').removeClass('selected');
$(this).addClass('selected');
}
var data = projecttable.cell(this.value,2).data();
alert(data);
});```