PDA

View Full Version : [CLOSED] Refresh tree using DirectEvent



bayoglu
Mar 04, 2013, 6:20 PM
Hello,

I went through many previous threats and examples. Unfortunately I could not make any solution work.
Can you provide an example to refresh a tree using code behind and direct events only?

One would be good for the example:
http://examples2.ext.net/#/TreePanel/Basic/Refresh_Static_Tree/

FYI:

Tree panel markup:


<ext:TreePanel ID="MyTree" runat="server" RootVisible="false">
</ext:TreePanel>


Method called during page load:


BuildTree(MyTree.Root, "init");


BuildTree method:


public static NodeCollection BuildTree(NodeCollection nodes, string TestString)
{
if (nodes == null)
{
nodes = new NodeCollection();
}

Node RootNode = new Node();
RootNode.Text = "MyRoot";
nodes.Add(RootNode);

Ext.Net.Node node = new Ext.Net.Node();
node.NodeID = TestString;
node.Text = TestString;
node.Leaf = true;

RootNode.Children.Add(node);
}



DirectEvent:



protected void RefreshMyTree(object sender, DirectEventArgs e)
{
BuildTree(MyTree.Root, "refresh");
}


I want to build the direct event to show "refresh" node.

Thanks.

Baidaly
Mar 05, 2013, 12:26 AM
Hello!

Please, read the following thread: http://forums.ext.net/showthread.php?22042-CLOSED-Refresh-TreePanel

bayoglu
Mar 05, 2013, 1:16 PM
Hello!

Please, read the following thread: http://forums.ext.net/showthread.php?22042-CLOSED-Refresh-TreePanel

Okay, I had asked if it was possible without the success event handler java script code below. Since it is a client-side re-organization, I guess this code is required if not refreshing the whole tree panel from the server side.

Thanks. Mark as closed please.



<script type="text/javascript">
var onSuccess = function (tree, result) {
var nodes = result.extraParamsResponse.nodes;

if (nodes.length > 0) {
tree.setRootNode(nodes[0]);
} else {
tree.getRootNode().removeAll();
}
};
</script>

Daniil
Mar 05, 2013, 1:38 PM
Hello,

I think it is possible using the SetRootNode method.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Refresh(object sender, DirectEventArgs e)
{
Node newRoot = new Node()
{
Text = "New Root",
Expanded = true,
Children =
{
new Node()
{
Text = "Some Node",
Leaf = true
}
}
};

this.TreePanel1.SetRootNode(newRoot);
}
</script>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:Button runat="server" Text="Refresh" OnDirectClick="Refresh" />

<ext:TreePanel ID="TreePanel1" runat="server">
<Root>
<ext:Node Text="Root (level 0)" Expanded="true">
<Children>
<ext:Node Text="Node1 (level 1)" Expanded="true">
<Children>
<ext:Node Text="Node1 (level 2)" Expanded="true">
<Children>
<ext:Node Text="Node1 (level 3)" Leaf="true" />
<ext:Node Text="Node2 (level 3)" Leaf="true" />
</Children>
</ext:Node>
</Children>
</ext:Node>
<ext:Node Text="Node2 (level 1)" Expanded="true">
<Children>
<ext:Node Text="Node1 (level 2)" Expanded="true">
<Children>
<ext:Node Text="Node1 (level 3)" Leaf="true" />
<ext:Node Text="Node2 (level 3)" Leaf="true" />
</Children>
</ext:Node>
</Children>
</ext:Node>
</Children>
</ext:Node>
</Root>
</ext:TreePanel>
</form>
</body>
</html>

bayoglu
Mar 05, 2013, 2:04 PM
Perfect. Thank you Daniil.


Hello,

I think it is possible using the SetRootNode method.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Refresh(object sender, DirectEventArgs e)
{
Node newRoot = new Node()
{
Text = "New Root",
Expanded = true,
Children =
{
new Node()
{
Text = "Some Node",
Leaf = true
}
}
};

this.TreePanel1.SetRootNode(newRoot);
}
</script>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:Button runat="server" Text="Refresh" OnDirectClick="Refresh" />

<ext:TreePanel ID="TreePanel1" runat="server">
<Root>
<ext:Node Text="Root (level 0)" Expanded="true">
<Children>
<ext:Node Text="Node1 (level 1)" Expanded="true">
<Children>
<ext:Node Text="Node1 (level 2)" Expanded="true">
<Children>
<ext:Node Text="Node1 (level 3)" Leaf="true" />
<ext:Node Text="Node2 (level 3)" Leaf="true" />
</Children>
</ext:Node>
</Children>
</ext:Node>
<ext:Node Text="Node2 (level 1)" Expanded="true">
<Children>
<ext:Node Text="Node1 (level 2)" Expanded="true">
<Children>
<ext:Node Text="Node1 (level 3)" Leaf="true" />
<ext:Node Text="Node2 (level 3)" Leaf="true" />
</Children>
</ext:Node>
</Children>
</ext:Node>
</Children>
</ext:Node>
</Root>
</ext:TreePanel>
</form>
</body>
</html>