PDA

View Full Version : [CLOSED] How to appendchild to leaf node from server



xeo4.it
Dec 03, 2014, 2:53 PM
Hi,
I need to appendchild to a leaf node from code behind,
see my example: if I click btnAppendChild1 the node is added without problem,
but if I click btnAppendChild2 the node is not added because node "C2" is a leaf.
Please help me
Thank you

Jimmy



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


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


<!DOCTYPE html>


<script runat="server">




protected void btnAppendChild1_click(object sender, DirectEventArgs e)
{


Ext.Net.Node newNode = new Ext.Net.Node();
newNode.NodeID = "Child1_1";
newNode.Text = "Child 1_1";
newNode.Icon = Icon.Table;
newNode.Leaf = true;
newNode.AllowDrop = false;
newNode.AllowDrag = true;


this.tree.GetNodeById("C1").AppendChild(newNode);

}


protected void btnAppendChild2_click(object sender, DirectEventArgs e)
{


Ext.Net.Node newNode = new Ext.Net.Node();
newNode.NodeID = "Child2_1";
newNode.Text = "Child 2_1";
newNode.Icon = Icon.Table;
newNode.Leaf = true;
newNode.AllowDrop = false;
newNode.AllowDrag = true;


this.tree.GetNodeById("C2").AppendChild(newNode);

}




</script>


<html>
<head runat="server">
<title>Basic TreePanel - Ext.NET Examples</title>
<link href="/resources/css/examples.css" rel="stylesheet" />
</head>
<body>
<ext:ResourceManager runat="server" />


<ext:TreeStore ID="TreeStore1" runat="server">
<Root>
<ext:Node Expanded="true" Text="Root">
<Children>
<ext:Node Text="Child 1" NodeID="C1" Expanded="true">
<Children>
<ext:Node Text="Child A" Leaf="true" />
</Children>
</ext:Node>
<ext:Node Text="Child 2" NodeID="C2" Leaf="true" >
</ext:Node>
</Children>
</ext:Node>
</Root>
</ext:TreeStore>

<ext:TreePanel
id="tree"
runat="server"
UseArrows="false"
Animate="true"
Mode="Remote"
RootVisible="true"
ContainerScroll="true"
Height="300"
Width="300"
StoreID="TreeStore1"
>

</ext:TreePanel>


<ext:Button ID="btnAppendChild1" runat="server" Text="Append child to child 1" >
<DirectEvents>
<Click OnEvent="btnAppendChild1_click" />
</DirectEvents>
</ext:Button>


<ext:Button ID="btnAppendChild2" runat="server" Text="Append child to child 2" >
<DirectEvents>
<Click OnEvent="btnAppendChild2_click" />
</DirectEvents>
</ext:Button>


</body>
</html>

Daniil
Dec 04, 2014, 8:31 AM
Hi Jimmy,

It appears .AppendChild() doesn't support appending a child to a leaf node on ExtJS level.

Though, with a few additional actions it is possible.

NodeProxy node = this.tree.GetNodeById("C2");
node.AppendChild(newNode);
node.Set("leaf", false);
node.Set("loaded", true);
node.Expand(false);

xeo4.it
Dec 04, 2014, 10:27 AM
Hi Daniil,
it works fine.
Thank you

Jimmy