Multiple tables - detect which has been clicked
Multiple tables - detect which has been clicked
I've got four dataTables on a page (each in a separate tab). Clicking an image in the last column of each table deletes that row via an Ajax call.
I'm using data properties on the image to point the Ajax call to the correct database table and record.
Finally, after the row has been deleted, the table is redrawn.
It's all working perfectly, but I'm currently having to redraw all four tables, because I don't know on which table object to call fnDraw();
I suspect there's an easy solution to this, but I can't think of it.
This is what I've currently got:
[code]
$('tbody img.delete').live('click', function (e) {
var sTable = $(this).data('table');
var sIndexColumn = $(this).data('column');
var id = $(this).data('id');
var sData = 'id='+id;
sData += '&sIndexColumn='+sIndexColumn;
sData += '&sTable='+sTable;
$.post('delete.php', sData, function(data) {
oTableOne.fnDraw();
oTableTwo.fnDraw();
oTableThree.fnDraw();
oTableFourfnDraw();
});
});
[/code]
Any help is much appreciated.
I'm using data properties on the image to point the Ajax call to the correct database table and record.
Finally, after the row has been deleted, the table is redrawn.
It's all working perfectly, but I'm currently having to redraw all four tables, because I don't know on which table object to call fnDraw();
I suspect there's an easy solution to this, but I can't think of it.
This is what I've currently got:
[code]
$('tbody img.delete').live('click', function (e) {
var sTable = $(this).data('table');
var sIndexColumn = $(this).data('column');
var id = $(this).data('id');
var sData = 'id='+id;
sData += '&sIndexColumn='+sIndexColumn;
sData += '&sTable='+sTable;
$.post('delete.php', sData, function(data) {
oTableOne.fnDraw();
oTableTwo.fnDraw();
oTableThree.fnDraw();
oTableFourfnDraw();
});
});
[/code]
Any help is much appreciated.
This discussion has been closed.
Replies
figured I could pass the name of the table object I need to refresh along with the other data on the img, and then call the refer to the object from the global window array like this:
[code]
var object = $(this).data('object');
window[object].fnDraw();
[/code]