Server data - Attaching a custom event to a datatable.

Server data - Attaching a custom event to a datatable.

rajzamiteshrajzamitesh Posts: 4Questions: 0Answers: 0
edited December 2013 in General
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

Replies

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    You're assigning the value returned by the function attach_click_row_event(), but you're not making that function return a value. You need to return sData.
  • rajzamiteshrajzamitesh Posts: 4Questions: 0Answers: 0
    problem solved by using fnDrawCallback

    [code]
    "fnDrawCallback": function( oSettings ) {
    alert( 'DataTables has redrawn the table' + form['name']);
    attach_click_row_event(form);
    },

    [/code]
This discussion has been closed.