Table refresh from JS data store.

Table refresh from JS data store.

ahrefahref Posts: 9Questions: 1Answers: 1

Hello,

I have a JS array data store and external events not ascociated with the table add/remove/change the data.

After this occurs i need to refresh/draw the table.

Here's a JsFiddle: http://jsfiddle.net/tnq73pt8/3/

Expected final result is for the table to have 7,8,9 as the top row.

I've tried recreating it. (recalling makeTable(), hence retrieve=true)
I've tried calling dataTable.draw()
I've tried calling, dataTable.clear(),dataTable.rows().add(data)

Super confused.

All my searches appear to refer to an older version which suggest calling fnDraw(false) which also doesnt work.

Thanks!

This question has an accepted answers - jump to answer

Answers

  • ahrefahref Posts: 9Questions: 1Answers: 1

    Please could I get an answer here?

    I'm so confused.

  • allanallan Posts: 63,683Questions: 1Answers: 10,498 Site admin

    You need to use the DataTables API to add data to the table - specifically use row.add() in this case. Updated fiddle.

    Allan

  • ahrefahref Posts: 9Questions: 1Answers: 1

    Hi Allan,

    Thanks for the info. This solution unfortunately is not what I had hoped for. I have a ton of outside events interacting with my datastore. It is similar to a Backbone Collection. It manages ajax, events, live updates etc and is constantly in sync with the server.

    Based on your answer it seems that DataTables copies the provided data into its own internals to use and then requires notification through row.add/remove to display any updates.

    I did find: http://stackoverflow.com/questions/9471743/how-do-i-tell-datatables-to-check-for-updated-data-in-a-backbone-collection#9524334

    Which uses an old a deprecated plugin.

    If I rewrote specifically fnServerData to use the new api I think I would have what I need.

    Would you agree, or is datatables simply not meant to be used like this?

    THANKS!

  • allanallan Posts: 63,683Questions: 1Answers: 10,498 Site admin
    Answer ✓

    DataTables does keep its own "collection" of the data it is to display as it has a number of bits of information that are required beyond the simple array of data that is passed in. Even if it were to use the array passed in, you would still need to call an API method to tell it to update, since the Array.observe method is currently only supported by Chrome. Long term I do want to support ECMAScript observables, but given that they are only on Chrome at the moment, it will likely be a little while off...

    Allan

  • ahrefahref Posts: 9Questions: 1Answers: 1

    OK, I'll check the performance of clearing the rows and looping through and adding them manually. If its ok I should be happy.

    Otherwise I'll sort something out.

    Thanks!

This discussion has been closed.