load on demand (Lazy load) functionality which is enabled in default. It reduces the bandwidth size when consuming huge data. It loads first level nodes initially, and when parent node is expanded, loads the child nodes based on the parentID/child member. |
<div class="control_wrapper">
<ejs-treeview id="main-menubar" :fields="fields" ref="treeviewInstance"></ejs-treeview>
</div>
data () {
var data = new DataManager({
url: 'https://localhost:44356/Home/Get',
adaptor: new WebApiAdaptor,
crossDomain: true,
});
return {
fields: {
dataSource: data, id: 'prog_id', text: 'prog_name', parentID: 'pid', hasChildren: 'hasChild'
}
}
}, |
|
[HttpGet]
public IEnumerable<OrdersDetails> Get()
{
var data = OrdersDetails.GetAllRecords().ToList();
var queryString = Request.Query;
if (queryString.Keys.Contains("$filter"))
{
string filter = string.Join("", queryString["$filter"].ToString().Split(' ').Skip(2)); // get filter from querystring
// filter the data based on the expand node id.
data = data.Where(d => d.pid.ToString() == filter).ToList();
return data;
}
else
{
// if the parent id is null.
data = data.Where(d => d.pid == null).ToList();
return data;
}
} |
|
UG Documentation |
|
|
Demo link |
|
|
Remote data |
|
|
API reference |
|
|
data () {
var remotedata = new DataManager({
url: 'https://localhost:44376/Home/Get',
adaptor: new WebApiAdaptor,
offline: true
});
return {
fields: { dataSource: remotedata, id: 'prog_id', text: 'prog_name', hasChildren: 'hasChild', parentId:'pid'},
}
}, |
|
nodeExpanding : function(args) {
if (args.isInteracted) {
// send the account id only on second level.
if(args.node.classList.contains("e-level-1")) {
var obj = { user: "1", account:args.nodeData.id };
}
// send the account id and subdirectory id on third level.
else if(args.node.classList.contains("e-level-2")) {
var obj = { user: "1", account: args.nodeData.id,subDirectory :args.nodeData.parentID };
}
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
// server side method to fetch the data.
data: JSON.stringify(obj),
dataType: "json",
success: function(data) {
var tree = document.getElementById("treeview").ej2_instances[0];
// Add the child data to the corresponding parent node.
tree.addNodes(data, args.nodeData.id);
},
error: function(xhr, err) {}
});
}
} |
|
[HttpPost]
public IActionResult Update([FromBody] customclass details)
{
var data1 = OrdersDetails.GetAllRecords().ToList();
// Fetch the data based on corresponding id.
data1 = data1.Where(d => d.user == details.user && d.account == details.account && d.subDirectory == details.subDirectory).ToList();
return Json(data1);
} |