initComplete & table reload

initComplete & table reload

stefanoBistefanoBi Posts: 5Questions: 2Answers: 0

Hi,

sorry for newbie's question, but i'm facing a problem.

I generate a table using ajax json data and i use initComplete to add some class and rewrite a column.
(maybe i may find a better solution but it work).

Now on data change i just call ajax.redraw() to fetch the new data, and it is ok, but i lose all job done by the function attached to initCompleted.

Now for a single table in the page i may just add a callback function to ajax.reload and i have the same job done, but i have multiple page and the code will never scale (it will explode with 6 tables).

There are nay way i can save the function called with initCompled in order to pass it to ajax.reload ?

I hope i made myself clear.

thanks in advance
/stefano

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Sure, you would just pass the function in would you not?

    var myCallback = function () { ... };
    
    // for initComplete
    initComplete: myCallback
    
    // for reload
    table.ajax.reload( myCallback );
    

    Allan

  • stefanoBistefanoBi Posts: 5Questions: 2Answers: 0

    Allan,

    thank for quick response. Yes this solve my problem, and was something i had tried.

    if i have 7 tables in the same code pages i should have 7 dedicate myCallback, not too bad, but i was looking to retrive the calback declared as anonyous function on calling the reload.
    Somthing like

    myTable1.ajax.reload(myTable.initComplete()).

    but i had limited javascript capability and i don't know if the callback had been stored&execute or just executed on declareation, If stored we can retrive it, Othervise we can't.

    Thanks for your great job!!!

    /stefano

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Answer ✓

    The callback is stored by DataTables internally, but it isn't accessible via the API. You would need to attach the function to the object yourself and then execute it.

    Allan

  • stefanoBistefanoBi Posts: 5Questions: 2Answers: 0

    Thanks Allan for help and detail.

    that is the way i'll use. Thanks again!

    ciao

This discussion has been closed.