Server data - Attaching a custom event to a datatable.
Server data - Attaching a custom event to a datatable.
rajzamitesh
Posts: 4Questions: 0Answers: 0
The following code is able to attach a click event to the table if the alert statement is uncommented.
Without the alert, the custom click event does not attach to the table.
[code]
function mk_data_table(form){
$('#' + form['name'] + '_table').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "getdata.php",
"fnServerParams": function ( aoData ) {
aoData.push( form['entity_name'],
form['atr_list'] );
},
"fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
attach_click_row_event(form);
},
"bDeferRender": true
} );
}
function attach_click_row_event(form){
//alert("attach_click_row_event");
form['data'] = $('#' + form['name'] + '_table').dataTable( );
form['data'].$('tr').click( function () {
var sData = form['data'].fnGetData( this );
alert( 'The cell clicked on had the value of '+sData );
} );
}
[/code]
getdata.php is my server side code for fetching data from db
How can I get desired behavior without the alert interrupt.
thanks
Without the alert, the custom click event does not attach to the table.
[code]
function mk_data_table(form){
$('#' + form['name'] + '_table').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "getdata.php",
"fnServerParams": function ( aoData ) {
aoData.push( form['entity_name'],
form['atr_list'] );
},
"fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
attach_click_row_event(form);
},
"bDeferRender": true
} );
}
function attach_click_row_event(form){
//alert("attach_click_row_event");
form['data'] = $('#' + form['name'] + '_table').dataTable( );
form['data'].$('tr').click( function () {
var sData = form['data'].fnGetData( this );
alert( 'The cell clicked on had the value of '+sData );
} );
}
[/code]
getdata.php is my server side code for fetching data from db
How can I get desired behavior without the alert interrupt.
thanks
This discussion has been closed.
Replies
[code]
"fnDrawCallback": function( oSettings ) {
alert( 'DataTables has redrawn the table' + form['name']);
attach_click_row_event(form);
},
[/code]