Refreshing Nodes

Refresh a node after its data has changed by call the node's refresh method. This sample demonstrates doing this in comparison to reloading the entire tree.

import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import * as wjNav from '@grapecity/wijmo.nav'; import { getData } from './data'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // create the tree let theTree = new wjNav.TreeView('#theTree', { itemsSource: getData(), displayMemberPath: 'header', childItemsPath: 'items' }); theTree.selectedItem = theTree.itemsSource[0]; // // refresh the node with new data document.getElementById('btnItemData').addEventListener('click', () => { theTree.selectedNode.refresh({ header: 'given itemData ' + Date.now(), items: [ { header: 'first child' }, { header: 'second child' } ] }); }); // // update the data, refresh the node document.getElementById('btnItemsSource').addEventListener('click', () => { let node = theTree.selectedNode, arr = node.itemsSource; // arr[node.index] = { header: 'updated itemData ' + Date.now(), items: [ { header: 'first child' }, { header: 'second child' } ] }; // node.refresh(); }); // // re-load the whole tree document.getElementById('btnReload').addEventListener('click', () => { theTree.loadTree(true); theTree.selectedItem = theTree.itemsSource[0]; }); } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo TreeView Nodes Refreshing</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div class="container-fluid"> <div class="row"> <div class="col-xs-6"> <div id="theTree"> </div> </div> <div class="col-xs-6"> <button id="btnItemData" class="btn btn-default"> Refresh with given item data </button><br /> <button id="btnItemsSource" class="btn btn-default"> Refresh with changed itemsSource </button><br /> <button id="btnReload" class="btn btn-default"> Re-load the TreeView </button> </div> </div> </div> </body> </html> // create some data export function getData() { return [ { header: 'Parent 1', items: [ { header: 'Child 1.1' }, { header: 'Child 1.2' }, { header: 'Child 1.3' } ] }, { header: 'Parent 2', items: [ { header: 'Child 2.1' }, { header: 'Child 2.2' } ] }, { header: 'Parent 3', items: [ { header: 'Child 3.1' } ] } ]; } .wj-treeview { font-size: 120%; margin-top: 8px; margin-bottom: 8px; padding: 6px; background: #f0f0f0; box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23); } body { margin-bottom: 24pt; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import { Component, Inject, enableProdMode, NgModule, ViewChild, AfterViewInit } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { WjNavModule, WjTreeView } from '@grapecity/wijmo.angular2.nav'; import { DataService } from './app.data'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent implements AfterViewInit { @ViewChild('theTree') theTree: WjTreeView; data: any[]; // constructor(@Inject(DataService) private dataService: DataService) { this.data = dataService.getData(); } // ngAfterViewInit() { this.theTree.selectedItem = this.theTree.itemsSource[0]; } // onItemDataClick(s: WjTreeView) { this.theTree.selectedNode.refresh({ header: 'given itemData ' + Date.now(), items: [ { header: 'first child' }, { header: 'second child' } ] }); } // onItemSourceClick() { let node = this.theTree.selectedNode, arr = node.itemsSource; // arr[node.index] = { header: 'updated itemData ' + Date.now(), items: [ { header: 'first child' }, { header: 'second child' } ] }; // node.refresh(); } // onReloadClick() { this.theTree.loadTree(true); this.theTree.selectedItem = this.theTree.itemsSource[0]; } } // @NgModule({ imports: [WjNavModule, BrowserModule], declarations: [AppComponent], providers: [DataService], bootstrap: [AppComponent] }) export class AppModule { } // enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo TreeView Nodes Refreshing</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Polyfills --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.min.js"></script> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html> <div class="container-fluid"> <div class="row"> <div class="col-xs-6"> <wj-tree-view #theTree [itemsSource]="data" [displayMemberPath]="'header'" [childItemsPath]="'items'"> </wj-tree-view> </div> <div class="col-xs-6"> <button class="btn btn-default" (click)="onItemDataClick()"> Refresh with given item data </button><br /> <button class="btn btn-default" (click)="onItemSourceClick()"> Refresh with changed itemsSource </button><br /> <button class="btn btn-default" (click)="onReloadClick()"> Re-load the TreeView </button> </div> </div> </div> import { Injectable } from '@angular/core'; // export class TreeItem { header: string; newItem?: boolean; img?: string; items?: TreeItem[] } // @Injectable() export class DataService { getData(): TreeItem[] { return [ { header: 'Parent 1', items: [ { header: 'Child 1.1' }, { header: 'Child 1.2' }, { header: 'Child 1.3' } ] }, { header: 'Parent 2', items: [ { header: 'Child 2.1' }, { header: 'Child 2.2' } ] }, { header: 'Parent 3', items: [ { header: 'Child 3.1' } ] } ]; } } .wj-treeview { font-size: 120%; margin-top: 8px; margin-bottom: 8px; padding: 6px; background: #f0f0f0; box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23); } body { margin-bottom: 24pt; } <template> <div class="container-fluid"> <div class="row"> <div class="col-xs-6"> <wj-tree-view :itemsSource="data" displayMemberPath="header" childItemsPath="items" :initialized="initialized"> </wj-tree-view> </div> <div class="col-xs-6"> <button class="btn btn-default" @click="onItemDataClick">Refresh with given item data</button> <br> <button class="btn btn-default" @click="onItemSourceClick">Refresh with changed itemsSource</button> <br> <button class="btn btn-default" @click="onReloadClick">Re-load the TreeView</button> </div> </div> </div> </template> <script> import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import Vue from 'vue'; import '@grapecity/wijmo.vue2.nav'; import * as wjCore from '@grapecity/wijmo'; import { getData } from './data'; // new Vue({ el: '#app', data: { data: getData() }, methods: { initialized(sender) { this.control = sender; this.control.selectedItem = this.control.itemsSource[0]; }, onItemDataClick() { this.control.selectedNode.refresh({ header: 'given itemData ' + Date.now(), items: [ { header: 'first child' }, { header: 'second child' } ] }); }, onItemSourceClick() { let node = this.control.selectedNode, arr = node.itemsSource; // arr[node.index] = { header: 'updated itemData ' + Date.now(), items: [ { header: 'first child' }, { header: 'second child' } ] }; // node.refresh(); }, onReloadClick() { this.control.loadTree(true); this.control.selectedItem = this.control.itemsSource[0]; } } }); </script> <style> .container-fluid .wj-treeview { font-size: 120%; margin-top: 8px; margin-bottom: 8px; padding: 6px; background: #f0f0f0; box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23); } body { margin-bottom: 24pt; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo TreeView Nodes Refreshing</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); </script> </head> <body> <div id="app"> </div> </body> </html> export function getData(){ return [ { header: 'Parent 1', items: [ { header: 'Child 1.1' }, { header: 'Child 1.2' }, { header: 'Child 1.3' }] }, { header: 'Parent 2', items: [ { header: 'Child 2.1' }, { header: 'Child 2.2' }] }, { header: 'Parent 3', items: [ { header: 'Child 3.1' }] } ]; } import './app.css'; import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; // import * as React from 'react'; import * as ReactDOM from 'react-dom'; // import * as wjNav from '@grapecity/wijmo.react.nav'; import { getData } from './data'; class App extends React.Component { constructor(props) { super(props); this.state = getData(); } render() { return (<div className="container-fluid"> <div className="row"> <div className="col-xs-6"> <wjNav.TreeView itemsSource={this.state} displayMemberPath="header" childItemsPath="items" initialized={this.initialized.bind(this)}> </wjNav.TreeView> </div> <div className="col-xs-6"> <button className="btn btn-default" onClick={this.onItemDataClick.bind(this)}>Refresh with given item data</button> <br /> <button className="btn btn-default" onClick={this.onItemSourceClick.bind(this)}>Refresh with changed itemsSource</button> <br /> <button className="btn btn-default" onClick={this.onReloadClick.bind(this)}>Re-load the TreeView</button> </div> </div> </div>); } initialized(sender) { this._control = sender; this._control.selectedItem = this._control.itemsSource[0]; } onItemDataClick() { this._control.selectedNode.refresh({ header: 'given itemData ' + Date.now(), items: [ { header: 'first child' }, { header: 'second child' } ] }); } onItemSourceClick() { let node = this._control.selectedNode, arr = node.itemsSource; // arr[node.index] = { header: 'updated itemData ' + Date.now(), items: [ { header: 'first child' }, { header: 'second child' } ] }; // node.refresh(); } onReloadClick() { this._control.loadTree(true); this._control.selectedItem = this._control.itemsSource[0]; } } ReactDOM.render(<App />, document.getElementById('app')); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>AutoComplete</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div id="app"></div> </body> </html> .container-fluid .wj-treeview { font-size: 120%; margin-top: 8px; margin-bottom: 8px; padding: 6px; background: #f0f0f0; box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23); } body { margin-bottom: 24pt; } export function getData() { return [ { header: 'Parent 1', items: [ { header: 'Child 1.1' }, { header: 'Child 1.2' }, { header: 'Child 1.3' } ] }, { header: 'Parent 2', items: [ { header: 'Child 2.1' }, { header: 'Child 2.2' } ] }, { header: 'Parent 3', items: [ { header: 'Child 3.1' } ] } ]; }