How to repeat fnInitComplete functions after a an fnReloadAjax?

How to repeat fnInitComplete functions after a an fnReloadAjax?

TonyFavillaTonyFavilla Posts: 3Questions: 0Answers: 0
edited August 2011 in General
Hello,
I've got 2 wonderfull tables working without any problem and in my page there is a button that lauch a function composed by

oTable.fnClearTable( 0 );
oTable.fnReloadAjax('...');
oTable.fnDraw();

And it's ok.
But after this i'd like to repeat the operations declared in fnInitComplete, how can i do?

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    instead of fnClearTable, you can re-initialize the table. if you include bDestroy in the init, it will remove the table contents (if any exist).

    if you save the init object into a variable, you can reuse it

    [code]
    $(document).ready(function() {
    oInit = {
    bDestroy: true,
    sAjaxSource: ' ... ',
    // etc.
    }

    $('#example').dataTable(oInit);

    $('#somebutton').click(function() {
    $('#example').dataTable(oInit); // re-init table.
    });

    });


    [/code]
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    fnReloadAjax has the option of a callback function which you could use to just rerun the calls then fnInitComplete does (also you shouldn't need the fnDraw call). One option if you don't want to duplicate code is to not use an anonymous function, but rather define your fnInitComplete function and then use a reference to it in both places.

    Allan
  • TonyFavillaTonyFavilla Posts: 3Questions: 0Answers: 0
    Thank you so much for your help!
    Even if the allan's one is more polite i used the fbas solution editing the sAjaxSource because it was easier to make it work correctly :)

    Thank you guys for your great work!
This discussion has been closed.