fnInitComplete to get access to already initialized dataTable not working as expected?

fnInitComplete to get access to already initialized dataTable not working as expected?

David123David123 Posts: 11Questions: 0Answers: 0
edited August 2013 in General
In Page load, I have initialized dataTable and fnInitComplete have called as expected.

Then I have clicked button, now I have passed result to already initialized dataTable(Using bRetrieve = true).

Now fnInitComplete isn't working in after initialized dataTable.
How to work fnInitComplete in bRetrieve?

I can't do that below issue in Test case. That's why i have posted my sample code.

My sample coding:

$(document).ready(function() {
//Now fnInitComplete is working. I got the alert now
var result = $.parseJSON(result);
var oTable = initTable();
BuildTopAccounts(result);

//Now fnInitComplete isn't working
$('.Buttons').click(function(){
var result = $.parseJSON(result);
var oTable = initTable();
BuildTopAccounts(result);
}};
} );

function initTable (){
return $('#contacttable').dataTable({
"sScrollY": calcDataTableHeight(),
"bAutoWidth": true,
"sScrollX": "800",
"bRetrieve": true,
"bDeferRender": true,
"aoColumnDefs": [
{"fnRender": getRank,"mDataProp": "rank", "sType": "Rank", "aTargets": [ 0 ],sDefaultContent: ""},
{"fnRender": getName,"sClass": "Name", "mDataProp": "Name", "bUseRendered":false,"aTargets": [ 1 ],sDefaultContent: ""}
],
"fnInitComplete": function (o) {
alert('fnInitComplete');
}
});
}
function BuildTopAccounts(result){
$('#contacttable').dataTable().fnClearTable();
$('#contacttable').dataTable().fnAddData(result);
}

Replies

  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin
    fnInitComplete fires once and once only for the life time of a table - when the initialisation is complete. bRetrieve tells DataTables to ignore any configuration that is passed in and just return the table instance object.

    Allan
  • David123David123 Posts: 11Questions: 0Answers: 0
    edited August 2013
    Thanks Allan.
    How to destroy or delete the old table values and again initialize table in new for passing table result.
    Because I need fnInitComplete for bRetrieve = true?
    Is it possible to do that?
  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin
    If you want to run a function after you get the table object, why not just run it after the call to get the DataTable object?
This discussion has been closed.