PDA

View Full Version : refresh cause tree panel blank



muhammadantoniussony
May 29, 2020, 5:48 AM
Greeting ....

I use this code to refresh my tree ..



<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Barang.aspx.cs" Inherits="WebApplication1.Setup.Barang" %>

<script runat="server">

[DirectMethod]
public string RefreshMenu()
{
Ext.Net.NodeCollection nodes = this.BuildTree(null);
return nodes.ToJson();
}

</script>


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script>

var refreshTree = function (tree) {
App.direct.RefreshMenu({
success: function (result) {
var nodes = eval(result);
if (nodes.length > 0) {
tree.setRootNode(nodes[0]);
}
else {
tree.getRootNode().removeAll();
}
}
});
};

</script>
</head>



I get that code from Ext.Net example #/TreePanel/Basic/Refresh_Static_Tree/ (https://examples5.ext.net/#/TreePanel/Basic/Refresh_Static_Tree/)

and build tree using Ext.Net example #/TreePanel/Loaders/Direct_Method/ (https://examples5.ext.net/#/TreePanel/Loaders/Direct_Method/)

it look like

25354

but after refresh using that code above, my tree become like this

25355

is there any solution .... ???

Thank's ....

fabricio.murta
May 29, 2020, 5:08 PM
Hello @muhammadantoniussony!

The two examples depict situations that are fairly "mutually exclusive". In one hand, you have a tree that loads on demand. In the other hand, you have a refresh loading the full tree.

In order to attain a "refresh" behavior in an environment like a loader-based tree, you'd have to, instead of reloading everything, to remember which local nodes are expanded, unload everything and then reload from root to the point you were.

One approach to get the behavior you want is:

1. start by "unloading" the tree; so that when "refresh" is clicked, it returns to its initial state. So basically you reset the tree without a full page reload.
2. Then you will have to save the expanded nodes somewhere else (an array, or a temporary store, you name it)
3. traverse the list of expanded nodes, from root down, calling the corresponding node in the refreshed tree's .expand() method, and letting the direct method run (wait all the server trip -- your best bet is to bind the continuation of the process to the direct method's callback)
4. if a expanded node is not found, then the process should stop (because it means the node was removed from the fresh version of the tree).

So, basically, you have to reload and repeat the user steps to expand the tree.

For performance, you can pass the list of expanded nodes to the refresh method and have it return the whole expanded tree.

Using the approach from the first example you pointed (TreePanel > Basic > Refresh_Static_Tree (https://examples5.ext.net/#/TreePanel/Basic/Refresh_Static_Tree/)) only supports bringing the whole tree, which is something you probably don't want -- after all you load just a level of the tree for a reason.

Hope this helps!

muhammadantoniussony
May 30, 2020, 4:47 PM
Greeting ...

I add .expand() method on code behind



Ext.Net.Node root = new Ext.Net.Node();
root.Text = "RooT";
root.Expanded = true; /* --- add this make root.children to show, cause it hide on RooT --- */
nodes.Add(root);


Thank you ....