selecting new rows
selecting new rows
Hello,
I use this bit of code to highlight and select a row.
[code]
/* Add a click handler to the rows - this could be used as a callback */
$("#example tbody td").click(function(event) {
$(oTable.fnSettings().aoData).each(function (){
$(this.nTr).removeClass('row_selected');
});
$(event.target.parentNode).addClass('row_selected');
});
[/code]
The original code I found in the forums was $("#example tbody tr").click but that did not work with JEditable (because JEditable fields were opening the textbox instead of allowing a click on the TR itself). So I changed it to td. That works on existing rows.
However, when I use fnAddData to add a new row, the new row is not selectable.
Is it possible to get the new row selected without refreshing the page?
Thanks
I use this bit of code to highlight and select a row.
[code]
/* Add a click handler to the rows - this could be used as a callback */
$("#example tbody td").click(function(event) {
$(oTable.fnSettings().aoData).each(function (){
$(this.nTr).removeClass('row_selected');
});
$(event.target.parentNode).addClass('row_selected');
});
[/code]
The original code I found in the forums was $("#example tbody tr").click but that did not work with JEditable (because JEditable fields were opening the textbox instead of allowing a click on the TR itself). So I changed it to td. That works on existing rows.
However, when I use fnAddData to add a new row, the new row is not selectable.
Is it possible to get the new row selected without refreshing the page?
Thanks
This discussion has been closed.
Replies
[code]
$("#example tbody td").live( 'click', function(event) {
...
[/code]
It's basically the same thing as in the first FAQ on the right hand side: http://datatables.net/faqs
Allan
So for instance clicking on the area marked
[code]<?php print $val['username']?> [/code]
results in the row being selected
but
[code]<?php print $val['username']?>[/code]
does not.
I'm not sure why setting the class or id would cause interference with the click or live events but it seems to be the case. It's also strange that the existing rows are selectable with the click event but not the live event.