bind rows on ajax reload
bind rows on ajax reload
stevegodin
Posts: 5Questions: 0Answers: 0
I am using this code to get clickable rows, called from fnInitComplete:
function createClickableRowsAllTickets() {
$(allTable.fnGetNodes()).click( function() {
alert('row clicked');
});
}
This works fine. However when I use fnReloadAjax to update the table the row clicks are no longer bound.
I tried to call the function once again on the callback of the fnReloadAjax but it doesn't work:
$("#alltickets input[type=checkbox]").click(function() {
allTable.fnReloadAjax('get_tickets', createClickableRowsAllTickets());
});
What is wrong?
function createClickableRowsAllTickets() {
$(allTable.fnGetNodes()).click( function() {
alert('row clicked');
});
}
This works fine. However when I use fnReloadAjax to update the table the row clicks are no longer bound.
I tried to call the function once again on the callback of the fnReloadAjax but it doesn't work:
$("#alltickets input[type=checkbox]").click(function() {
allTable.fnReloadAjax('get_tickets', createClickableRowsAllTickets());
});
What is wrong?
This discussion has been closed.
Replies
I tried to use delegate and live to get it to work, but still having trouble so that might not be the real problem. My guess:
When I call createClickableRowsAllTickets() I guess allTable has not been updated because allTable.fnGetNodes() still returns the old rows (as it looked before the fnReloadAjax call)
Code should be:
$("#alltickets input[type=checkbox]").click(function() {
allTable.fnReloadAjax('get_tickets', function() { createClickableRowsAllTickets();}, null);
});
instead of:
$("#alltickets input[type=checkbox]").click(function() {
allTable.fnReloadAjax('get_tickets', createClickableRowsAllTickets());
});
note the use of function() in the callback parameter.
[code]
$("#alltickets input[type=checkbox]").click(function() {
allTable.fnReloadAjax('get_tickets', createClickableRowsAllTickets);
});
[/code]
i.e. passing the `createClickableRowsAllTickets` function, rather than the result of calling it. Good to hear you got it working.
Allan