Hi,
We are using a EJ2 Javascript ES5 treeview control which is getting populated through hierarchical data obtained from a SQL server database query. Whenever we need to add/update/delete any node, we first update our database using stored procedures, if successful, need to refresh the treeview(or atleast a node along with child elements).
To accomplish this, we have stored the json(which is being used as datasource to the tree) in a javascript variable which we repopulate everytime whenever database is updated. Now when we try refresh and refreshNode methods to reflect the changes into tree, it does not work.
Below is the code sample for the same.
|
var treeInstance = ej.base.getComponent(document.querySelector('#tree'),'treeview');
treeInstance.fields = { dataSource: hierarchicalData, id: 'id', text: 'name', child:'subChild' }; |
|
function changeDataSource() {
// Get instance of TreeView component
var treeInstance = ej.base.getComponent(
document.querySelector('#tree'),
'treeview'
);
//Fetches the updated datasource
var treeData = treeInstance.getTreeData();
treeInstance.fields = {
dataSource: treeData,
id: 'id',
text: 'name',
child: 'subChild'
};
} |
Hi,
We followed your steps for making the syncfusion treeview state persistence but it is not working for us. The variable "treeData" does not contains the updated data after adding new node. Therefore, tree is not getting updated. Can you please tell us what are we doing wrong here?
Below is the code sample for the same.
|
function dataSourceChanged(args) {
//Return updated data source.
console.log(args.data);
} |
Hi,
In the sample ' https://stackblitz.com/edit/iuglw8-rtccvc?file=index.js ' you are using addNodes method for adding new nodes in tree. Is it possible to do the same without using addNodes method and also select the newly added node as well? If yes then how?
Also, the data behind the tree may be updated in the database from other sources as well (as it is a multi user application). So, how to periodically refresh the data without sacrificing the tree state at client side.
Thanks,
Shradha Chauhan
|
document.getElementById('btn').addEventListener('click', (e) => {
var nodeId = 'tree_' + index;
var item = { id: nodeId, name: 'NewItem' + index };
hierarchicalData.push(item);
treeObj.refresh();
index++;
//To select the newly added node.
treeObj.selectedNodes = [nodeId];
}); |