Hi,
how can I call a "Demo" controller method via remotedata (example "DataSource(da => da.Url("Demo").Adaptor("UrlAdaptor")") every time the node is expanded, to populate it? And not just the first time like with the "OnDemand" property.
Best Regards,
Massimo
Hi, Kanagambigai,
Thanks for response, yes I understand how you mean the "LoadOnDemand" and for another function I need to write it is fine.
The problem is that in this function I have a list of dynamic elements, not static, that can change even 1sec after creating it, they are the list of records associated to the parent record. For this I need to create a method to refresh the node, a method that must be triggered even when the node is expanded. The records will never be many, so there are no performance problems. Otherwise I have to reload the whole list of all elements every time, but in this case I have to keep in memory the state of all open and closed nodes.
It would be useful to have like a "LoadOnDemand=Always" property that calls the method at every load.
I hope I have explained myself.
Regards,
Massimo
|
function onNodeExpanding(args) {
if ((args.node.querySelectorAll(".e-icons.e-icon-expandable").length > 0)) {
xmlRequest(args.node, args.node.getAttribute("data-uid"));
}
}
function xmlRequest(currentTarget, parentID) {
var request = new XMLHttpRequest();
request.open('POST', '/api/SampleData?id=' + parentID, true);
var proxy = document.getElementById('treeview').ej2_instances[0];
var parent = currentTarget;
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
request.onload = function () {
if (request.status >= 200 && request.status < 400) {
// Success!
var resp = request.responseText;
proxy.addNodes(JSON.parse(resp), parent);
} else {
}
};
request.onerror = function () {
};
request.send();
} |
This is exactly what I was looking for, thank you.
I need to delete all the elements of the parent node before loading the new ones though. I've searched the various docs and forums but haven't found anything.
I've read that with ".removeNodes" I can delete the current node, but how can I delete all the child elements of a node without deleting the node itself?
Regards,
Massimo
|
nodeExpanded: function (args) {
//Pass the child nodes details here to remove
this.removeNodes(['01-03-01', '01-03-02', '01-03-03']);
} |
OK, thanks.
Regards,
Massimo