|
[ts]
@ViewChild('tree')
public tree: TreeViewComponent
public data: { [key: string]: Object }[] = [];
public dataManager: any = new DataManager({
//assign your Web API service URL here
url: 'http://localhost:64599/api/TreeViewData/GetAllData',
adaptor: new UrlAdaptor,
crossDomain: true,
headers: [{ Authorization: 'Bearer ' + JSON.parse(localStorage.getItem('currentUser')).authToken }]
}).executeQuery(new Query()).then((e: any) => {
//assign the returned data to TreeView data source
this.tree.fields.dataSource = e.result as { [key: string]: Object }[];
});
public field:Object = { dataSource: this.data, id: 'id', parentID: 'parent_Id', text: 'text', hasChildren: 'leaf' };
|
|
[ts]
public nodeAttr: { [key: string]: string } = {'class': 'firstnode', 'style': 'background: red'};
// Data source for TreeView component
public countries: Object[] = [
{ id: 1, name: 'Australia', hasChild: true, expanded: true },
{ id: 2, pid: 1, name: 'New South Wales' },
{ id: 3, pid: 1, name: 'Victoria' },
{ id: 4, pid: 1, name: 'South Australia' },
{ id: 6, pid: 1, name: 'Western Australia' },
{ id: 7, name: 'Brazil', hasChild: true, htmlAttr: this.nodeAttr },
{ id: 8, pid: 7, name: 'Paraná' }
];
public field:Object ={ dataSource: this.countries, id: 'id', parentID: 'pid', text: 'name', hasChildren: 'hasChild', htmlAttributes: 'htmlAttr' };
|
|
[html]
<ejs-treeview id="default" #tree [fields]='field' (drawnode)="onDrawNode($event)"></ejs-treeview>
[ts]
public onDrawNode(args: DrawNodeEventArgs) {
//check the returned Boolean data type of data from Web API for specific node
//ex: we have returned the "isBold" data in data source
if (args.nodeData["isBold"]) {
args.node.classList.add("text-bold");
}
}
[css]
.e-treeview .text-bold > .e-text-content .e-list-text {
font-weight: bold;
}
|
|
[ts]
public dataManager: any = new DataManager({
url: 'http://localhost:64599/api/TreeViewData/GetAllData',
adaptor: new UrlAdaptor,
crossDomain: true,
offline: true,
headers: [{ Authorization: 'Bearer ' + JSON.parse(localStorage.getItem('currentUser')).authToken }]
}).executeQuery(new Query()).then((e: any) => {
//assign the returned data to TreeView data source
this.tree.fields.dataSource = e.result as { [key: string]: Object }[];
});
|