combining features: ajax + click handling

combining features: ajax + click handling

NeilForsythNeilForsyth Posts: 1Questions: 0Answers: 0
edited March 2009 in General
I'm probably missing a basic datatables (or jquery) concept here, but after loading data via ajax, my click handler doesn't work:

[code]
$(document).ready(function() {
$('#tblsearch').dataTable( {
"bProcessing": true,
"sAjaxSource": 'list-searchable.json.php',
"aoColumns": [
/* Country */ null,
/* State */ null,
/* City */ null,
/* Name */ null,
/* Phone */ null,
/* Model */ null
]
});
$('#tblsearch tr').click( function () {
alert("you clicked");
if ( $(this).hasClass('row_selected') )
$(this).removeClass('row_selected');
else
$(this).addClass('row_selected');
});
});
[/code]

The alert() is never fired, let alone the row_selected classes. Eventually i'll want to take this further this by manipulating other items on the page depending on the selected row(s) from the DataTable.

Replies

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Hi,

    It's slightly odd that none of the rows would have a click handler on them (I would have expected some, but not all would from that). However, what I think you are looking for is shown in the adding event after initialisation example:

    http://datatables.net/examples/example_events_post_init.html

    [code]
    $( oTable.fnGetNodes() ).click( function () {
    /* whatever */
    } );
    [/code]

    should do it for you.

    Allan
  • zygimantaszygimantas Posts: 33Questions: 0Answers: 0
    NeilForsyth, have you tried to bind event by using new JQuery "live" function? (http://docs.jquery.com/Events/live#typefn)
This discussion has been closed.