So in my datatable, I have buttons that allow the record to be edited. I am using JQuery to style and give functions to the button click. The only way to get the JQuery to be applied to the buttons, is by putting the code inside the fnDrawCallback option of the table. However, it causes multiple instances of the functions! For instance, just to test I am creating an alert to give me the button id (which is the record id) when the button is clicked. And instead of just alerting me ONCE, it gives me several alerts!
Any ideas?
*As a side note, I have tried declaring the functions inside the fnInitComplete option but that only applies the function to the first set of records that is displayed (i.e. 10). Once I show more records or go to the next page, the functions dont work on those records.
var tfTable = $('.mypbhs_truforms').dataTable({
"bProcessing": true,
"sAjaxSource": 'sql/mypbhs_truforms.php?accountid=<?PHP echo $accountid;?>',
"aaSorting": [[ 1, "asc" ]],
"bJQueryUI": true,
"sPaginationType": "full_numbers",
//"bStateSave": true, //Use a cookie to save current display of items
"aoColumns": [
{"asSorting": [ ], "sClass":"center"},
null,
null,
null,
null,
null,
{"asSorting": [ ], "sClass":"center"},
],
"fnDrawCallback": function(){
//EDIT OFFICE FORM
$('.mypbhs_edit_truform_button').click(function(){
var tf_id = $(this).attr('id');
alert(tf_id);
});
},
"bScrollCollapse": true,
"sScrollX": "100%",
"fnInitComplete": function() {
tfTable.fnAdjustColumnSizing();
}
});