Update a table with a new values using "data" option

Update a table with a new values using "data" option

dimgldimgl Posts: 3Questions: 1Answers: 0

I'm having a frustrating issue where once I've initialized a DataTable with the "data" option, I am unable to refresh the data inside. I would love to be able to just wipe all of the data and insert a new object.

I've included a link with the problem which should make it easy to understand what I'm trying to do. Basically, I've downloaded new data from the server and I want to update the data inside of DataTables.

http://live.datatables.net/rajafawe/2/edit

Any help is really appreciated. Thank you.

Answers

  • dimgldimgl Posts: 3Questions: 1Answers: 0

    Well, I figured it out.

    var foo = [{name: "John Smith"}];
    var table = $('table').DataTable({
      "data": foo,
      "columns": [{"data": "name"}]
    }); // DOM renders it
    
    // Some time has passed and we want to update with new data
    var bar = [{name: "Margaret Thatcher"}];
    table.clear();
    bar.forEach(table.row.add);
    table.draw();
    
This discussion has been closed.