row select doesn't work with fnAddData

row select doesn't work with fnAddData

uriyuriy Posts: 3Questions: 0Answers: 0
edited May 2011 in General
I am very glad to use DataTables.
I have troubles.
I am using example http://datatables.net/examples/api/select_row.html.
It works fine for rows created statically by html page.
I also create rows by $('#example').dataTable().fnAddData().
For this rows doesn't work function:
[code]
$('#example tr').click( function() {
if ( $(this).hasClass('row_selected') )
$(this).removeClass('row_selected');
else
$(this).addClass('row_selected');
} );
[/code]

$('#example tr').click( function() works only for rows created statically by html.
Is it feature or bug?

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Neither :-). It just a result of not having an event listener on your new row (the example wasn't created with that in mind). Easiest way to address it is to use live events rather than the static one in my example.

    Allan
  • uriyuriy Posts: 3Questions: 0Answers: 0
    Thank you Allan.
    This works:
    [code]
    $('#example tr').live('click', function() {
    if ( $(this).hasClass('row_selected') )
    $(this).removeClass('row_selected');
    else
    $(this).addClass('row_selected');
    }
    [/code]
    I make little bit donation for you. Thanks.
This discussion has been closed.