fnDrawCallback listener adding

fnDrawCallback listener adding

spiritastirspiritastir Posts: 3Questions: 0Answers: 0
edited June 2011 in General
How to add fnDrawCallback listener after table is initialized.

I mean I already have a table. How to add smth like

"fnDrawCallback": function() {
alert( 'DataTables has redrawn the table' );
}

Thanks.

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    It's not really the "normal" thing to do since there isn't a documented API for it, but this is how you can do it:

    [code]
    oTable.fnSettings().aoDrawCallback.push( {
    "fn": function (oSettings) { .... },
    "sName": "user"
    } );
    [/code]

    Allan
  • spiritastirspiritastir Posts: 3Questions: 0Answers: 0
    Thanks for the fast reply!

    I've got one more idea.
    Where all table data is stored? Is it possible to destroy the table after the page is loaded and create new one using all the data from the first one?
    I am working with one CMS and I can not change it's core files. So I want to take their table at user side and redraw it.
    So is it possible to create a new table from the old one (which we have when the page is loaded)?

    DataTables is a great tool! And I want to learn it deeper after I will finish this my project =)
  • spiritastirspiritastir Posts: 3Questions: 0Answers: 0
    edited June 2011
    Here is info on how to destroy current table.

    http://datatables.net/forums/discussion/comment/6034#Comment_6034

    How to create a new one after this using existing data?
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    You can use the API methods fnGetData and fnDestroy ( http://datatables.net/api ) to get the data from a table and then destroy an existing table. With the return from fnGetData you have a Javascript array so you can give that to a new DataTables (the aaData property) or generate a new HTML table and run DataTables over that.

    Allan
  • spiritastirspiritastir Posts: 3Questions: 0Answers: 0
    I created a script that simply destroys old (default) table and creates a new one. And this works perfect. Now I have another problem.
    I need to hide some rows and show them after button click. So there are two ways:
    1. Simply hide rows ( is this possible with datable tools? ).
    2. Use filtering to hide those rows ( is this possible to use two filters together - one filter that uses input field and another that temporary hides some rows? ).
This discussion has been closed.