Create and remove DataTable dynamically

Create and remove DataTable dynamically

dkeandkean Posts: 2Questions: 0Answers: 0
edited March 2012 in DataTables 1.9
I am using a jQuery DataTable on a site, but all the data in the table changes every time I press a different hyperlink. So rather than delete the rows and add them one by one, is there a way to dynamically remove the entire DataTable and recreate another one with all the data with an array.

The code here is just plan old static stuff but I know how to dynamically fetch the array, let's say the array looks like this when I get it back from python/cherryPy:
ar[n]=["col1","col2","col3","col4",..."coln"] :


The code below is the static code for creating the DataTable in the HTML (static)...




*ProposalVote For ddA


BlaBlaBlaMore BlaBlaBla CheeCheeChee ChooChoo... LaLaLa





How would I do this in JavaScript or jQuery?


Dennis

Replies

  • sushilsushil Posts: 1Questions: 0Answers: 0
    I have similar scenario too, in my case I am getting html having all the table, thead, and rows from the server, and need to replace the existing html/table to which the DataTable is attached. I need this urgently, your quick reply is highly appreciated. Thanks.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited March 2012
    Have you looked at the bDestroy or fnDestroy options to remove the old DataTable, and then you can initialise a new one in its place?

    Allan
This discussion has been closed.