[HTML]
<ej-treeview [fields]="fields"></ej-treeview>
[Script]
//data binding
this.localData = [
{ id: 1, name: 'Local Disk(C:)', hasChild: true, customField:"Custom-Info" },
{ id: 2, pid: 1, name: 'Folder 1' },
{ id: 3, pid: 1, name: 'Folder 2' }];
this.fields = { id: 'id', parentId: 'pid', text: 'name', hasChild: 'hasChild', dataSource: this.localData};
//Get the custom field for Treeview component
var treeObj = $("#tree1").data("ejTreeView");
var node = treeObj.getTreeData(“1”); //get the given node object
alert("The Customfield of node '" + node[0].name + "' is: '" + node[0].customField + "'"); |
[HTML]
<div id="treeview"> </div>
[Script]
//Configure the DataManager
var dataManager =new ej.DataManager({
url: "WebAPI Url",
crossDomain: true,
adaptor: new ej.WebApiAdaptor()
});
// Query to fetch data from WebAPI.
var query=new ej.Query().select(["expanded", "hasChild", "id","name","pid"]).from("TreeViewData").take(5);
var queryPromise = dataManager.executeQuery(query);
// Convert the WebAPI data into local data
queryPromise.done(function(e){
var retriveData = (e.xhr && e.xhr.responseJSON && e.xhr.responseJSON.d) ? e.xhr.responseJSON.d : (e.result ? e.result : []);
$("#treeview").ejTreeView({
loadOnDemand:true, //Bind the data and LoadOnDemand property for treeview
fields: {
// Assign data source and mapping the data source fields.
dataSource: retriveData, id: "id", text: "name", parentId: “pid",expanded:"expanded",hasChild:"hasChild"
}
});
});
|