How do you update a table with JS variable ?

How do you update a table with JS variable ?

cmDataTablecmDataTable Posts: 2Questions: 0Answers: 0
edited July 2013 in General
Hello,

I would know how do you update a table with JS variable ?

I try :
var myTab1 =[
{"var1":"0","var2":"0","var3":"0","var4":"0","var5":"0"},
{"var1":"0","var2":"0","var3":"0","var4":"0","var5":"0"},
{"var1":"0","var2":"0","var3":"0","var4":"0","var5":"0"}
];

var $myTable = $('#myTable').dataTable({
"sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap",
"aoColumns": [
{"mData": "var1" },
{"mData": "var2" },
{"mData": "var3" },
{"mData": "var4" },
{"mData": "var5" }
],
"aaData":myTab1
});

myTab1[0].var1="foo";
myTab1[1].var3="foo";
myTab1[2].var5="foo";
myTab1[3]= {"var1":"0","var2":"0","var3":"0","var4":"0","var5":"0"};

$myTable.fnClearTable();
$myTable.fnAddData(myTab1);

Is it the best way ?

Replies

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Currently in DataTables 1.9 that won't work I'm sorry to say. DataTables 1.9 takes an independent copy of the data, thus breaking the reference.

    The good news is that DataTables 1.10 doesn't do that. The bad news is that it is pre-beta. You are very welcome to try it, but there are a few known issues... :-)

    In 1.10 you'd just call invalidate on the row, or the whole table:

    [code]
    table.rows().invalidate().draw();
    [/code]

    And DataTables will read the latest data from your array source and use it in the table.

    You can try 1.10 from git here: https://github.com/DataTables/DataTables/blob/1_10_wip/media/js/jquery.dataTables.js

    Allan
  • cmDataTablecmDataTable Posts: 2Questions: 0Answers: 0
    ok, i thank you
This discussion has been closed.