selecting new rows

selecting new rows

jriverajrivera Posts: 14Questions: 0Answers: 0
edited March 2010 in General
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

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Try using live events:

    [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
  • jriverajrivera Posts: 14Questions: 0Answers: 0
    Thanks I tried that. But in addition to the new row not being selectable, the existing columns with JEditable no longer highlight.
    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.
This discussion has been closed.