Change the data set in javascript and update data table with new values.
Change the data set in javascript and update data table with new values.
ketanmhatre
Posts: 4Questions: 0Answers: 0
Hi,
I am drawing one data table with json data. I have two such data sets.
Initially I will be drawing table with first data set. Now clicking on link I need to populate table with another data set.
Not sure how do I do it. Can you pls help.
var aDataSet = [
["Act one ", "700", "1000","300"],
["Act two", "700", "1000","300"],
["Act three", "700", "1000","300"],
["Acct four", "700", "1000","300"]
];
var aDataSetNew = [
["Act one new ", "700", "1000","300"],
["Act two new", "700", "1000","300"],
["Act three new", "700", "1000","300"],
["Acct four new", "700", "1000","300"]
];
$('#projDataTable').dataTable( {
"aaData": aDataSet,
"sScrollY": "200px",
"sDom": 't',
"bScrollInfinite": true,
"bDeferRender": true,
"iDisplayLength": -1,
"bSort": false,
"aoColumns" : [
{ },
{ sClass: "alignRight" },
{ sClass: "alignRight" },
{ sClass: "alignRight" }
]
} );
LOAD NEW DATA
Account Name1
Value one
value two
Net total
I am drawing one data table with json data. I have two such data sets.
Initially I will be drawing table with first data set. Now clicking on link I need to populate table with another data set.
Not sure how do I do it. Can you pls help.
var aDataSet = [
["Act one ", "700", "1000","300"],
["Act two", "700", "1000","300"],
["Act three", "700", "1000","300"],
["Acct four", "700", "1000","300"]
];
var aDataSetNew = [
["Act one new ", "700", "1000","300"],
["Act two new", "700", "1000","300"],
["Act three new", "700", "1000","300"],
["Acct four new", "700", "1000","300"]
];
$('#projDataTable').dataTable( {
"aaData": aDataSet,
"sScrollY": "200px",
"sDom": 't',
"bScrollInfinite": true,
"bDeferRender": true,
"iDisplayLength": -1,
"bSort": false,
"aoColumns" : [
{ },
{ sClass: "alignRight" },
{ sClass: "alignRight" },
{ sClass: "alignRight" }
]
} );
LOAD NEW DATA
Account Name1
Value one
value two
Net total
This discussion has been closed.
Replies
Allan
oTable.fnClearTable();
and the use fnAddData in a loop to add rows from another data set.
Is there any better way to do it.
$.each(aDataSet1, function(i, item) {
$('#projDataTable').dataTable().fnAddData(
aDataSet1[i]
);
});
Is this the correct way to do it. Or is there any other better way just to change dataset and update table.
And thanks for so quick reply Allan.