combining features: ajax + click handling
combining features: ajax + click handling
NeilForsyth
Posts: 1Questions: 0Answers: 0
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.
[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.
This discussion has been closed.
Replies
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