jQWidgets Forums
jQuery UI Widgets › Forums › Angular › Tree source is not updated
Tagged: angular tree, Tree source
This topic contains 3 replies, has 2 voices, and was last updated by Martin 6 years, 11 months ago.
-
Author
-
Hi,
I have updated the tree node with new node, but the treesource is not getting updated and when i reload newnode is not shown.
<jqxTree #objTree [allowDrag]=”false” [allowDrop]=”false”
[width]=”‘100%’” [height]=”‘100%’” [theme]=”appTheme” [source]=”treeSource”>this.objTree.addTo(newnode, node.element);
this.objTree.refresh();
this.treeSource = this.objTree.source();Thanks,
KavyaHello Kavya,
To keep the changes when you reload the component you have to update the data on your server, too.
The source doesn’t get updated when you add new nodes in the tree.Please, when you post your questions, do it in one post only, not in several categories.
Thank you!Best Regards,
MartinjQWidgets Team
http://www.jqwidgets.com/Hi Martin,
[Please, when you post your questions, do it in one post only, not in several categories.]
Sure will take care.how do i update the source? as i’m using source to update the data on server.
Thanks,
KavyaHello Kavya,
As the source doesn’t get updated when you add new nodes to the tree, you will have to update it manually.
Here is an example of how you can do it:@ViewChild('objTree') objTree: jqxTreeComponent; treeSource: any[] = [ { label: "Mail", expanded: true, items: [ { label: "Calendar" }, { label: "Contacts", selected: true } ] }, { label: "Inbox", expanded: true, items: [ { label: "Admin" }, { label: "Corporate" }, { label: "Finance" }, { label: "Other" }, ] }, { label: "Deleted Items" }, { label: "Notes" }, { label: "Settings" }, { label: "Favorites" } ]; addNode = () => { let source = { label: 'source', items: this.treeSource }; let selectedItem = this.objTree.getSelectedItem(); let node = this.searchSource(source, selectedItem.label); console.log(node); if (!node.items) { node.items = []; } node.items.push({ label: 'Item' }); if (selectedItem != null) { this.objTree.addTo({ label: 'Item' }, selectedItem.element); this.objTree.refresh(); } else { this.objTree.addTo({ label: 'Item' }, null); this.objTree.refresh(); } console.log(this.treeSource); } searchSource = (node, label) => { if (node.label === label) { return node; } else if (node.items != null) { var i; var result = null; for (i = 0; result == null && i < node.items.length; i++) { result = this.searchSource(node.items[i], label); } return result; } return null; }
Best Regards,
MartinjQWidgets Team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.