How do you update a table with JS variable ?
How do you update a table with JS variable ?
cmDataTable
Posts: 2Questions: 0Answers: 0
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 ?
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 ?
This discussion has been closed.
Replies
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