PDA

View Full Version : [CLOSED] Change node parent instead of removing and re-adding?



extnetuser
May 28, 2013, 5:43 PM
Hi,

I have a TreePanel Leaf that I want to move from one parent Node to another.
Is this possible without removing and readding it?

Thank you

RCN
May 28, 2013, 8:19 PM
I think that it's not possible.

RCN
May 28, 2013, 8:39 PM
In case of you need an example:



<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
<script type="text/javascript">
var move = function () {
var source = App.TreePanel1.store.getNodeById('_aa');

var sourceParent = source.parentNode;
sourceParent.removeChild(true);
sourceParent.set('leaf', true);

var referenceNode = App.TreePanel1.store.getNodeById('_b');
source = referenceNode.appendChild(source);
}
</script>
</head>
<body>
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:TreeStore ID="TreeStore1" runat="server">
<Root>
<ext:Node Expanded="true">
<Children>
<ext:Node NodeID="_a" Text="Ext.Net" Expanded="true">
<Children>
<ext:Node NodeID="_aa" Text="Ext" Leaf="true" />
</Children>
</ext:Node>
<ext:Node NodeID="_b" Text="core" Expanded="true">
<Children>
<ext:Node NodeID="_bb" Text="Sencha" Leaf="true" />
</Children>
</ext:Node>
</Children>
</ext:Node>
</Root>
</ext:TreeStore>
<ext:Viewport ID="Viewport1" runat="server" Margins="0 0 10 0">
<LayoutConfig>
<ext:VBoxLayoutConfig Align="Center" Pack="Center" />
</LayoutConfig>
<Items>
<ext:Button ID="Button1" Text="Move" runat="server">
<Listeners>
<Click Handler="move();" />
</Listeners>
</ext:Button>
<ext:TreePanel ID="TreePanel1" runat="server" Title="TreePanel" Width="300" Height="200"
Margin="10" RootVisible="false" Lines="false" UseArrows="false" StoreID="TreeStore1" />
</Items>
</ext:Viewport>
</body>
</html>




namespace SandBox.Controllers
{
public class ExampleController : System.Web.Mvc.Controller
{
public ActionResult Index()
{
return View();
}

public StoreResult LoadTreeFakeChildren()
{
NodeCollection nodes = new NodeCollection(false);

for (int index = 1; index < 6; index++)
{
Node no = new Node();
no.NodeID = index.ToString() + DateTime.Now.Second;
no.CustomAttributes.Add(new ConfigItem { Name = "Task", Value = no.NodeID, Mode = ParameterMode.Value });
no.CustomAttributes.Add(new ConfigItem { Name = "Column1", Value = Guid.NewGuid().ToString(), Mode = ParameterMode.Value });
nodes.Add(no);
}

return new StoreResult { Data = nodes.ToJson() };
}
}
}

Baidaly
May 29, 2013, 3:46 AM
Hello!

Thank you Raphael for your sample!

Please, @extnetuser try Raphael's example? Does it work for you?

Daniil
May 29, 2013, 6:01 AM
Hi,

Well, changing a node's parent supposes removing from an old parent and adding to a new one. So, I agree with Raphael that it is not possible to change a node's parent without those operations.

Please clarify why is it going to be a problem?

RCN
May 29, 2013, 12:44 PM
Thank you Raphael for your sample!

You're welcome.


@ExtNetUser, let us know if you need further assistance.