PDA

View Full Version : [CLOSED] How to load treepanel with httphandler with selected node?



jchau
Dec 10, 2013, 8:44 PM
I am loading a treepanel via ajaxproxy and hitting an url that's a httphandler. In the httphandler, I am sending back the NodeCollection.ToJson() to populate the tree. Is it possible to also send back the selected node? Or do I need to do another request?

Baidaly
Dec 10, 2013, 9:17 PM
Hello!

I think it's not possible but you can do it without extra request. You need to mark required nodes as selected and listen Load event:


<ext:TreePanel
ID="TreePanel1"
runat="server"
Title="Tree"
Height="500"
Width="200"
Border="false">
<Store>
<ext:TreeStore runat="server">
<Proxy>
<ext:AjaxProxy Url="TreeLoader.ashx" />
</Proxy>
<Listeners>
<Load Handler="
records.forEach(function(record) {
if (record.get('selected'))
App.TreePanel1.getSelectionModel().select(record);
})"/>
</Listeners>
</ext:TreeStore>
</Store>
<Root>
<ext:Node NodeID="0" Text="Root" />
</Root>
</ext:TreePanel>

TreeLoader.ashx

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/json";
string nodeId = context.Request["node"];

if (!string.IsNullOrEmpty(nodeId))
{
NodeCollection nodes = new NodeCollection(false);

for (int i = 1; i < 6; i++)
{
Node asyncNode = new Node();
asyncNode.Text = nodeId + i;
asyncNode.NodeID = nodeId + i;
nodes.Add(asyncNode);
}

for (int i = 6; i < 11; i++)
{
Node node = new Node();
node.Text = nodeId + i;
node.NodeID = nodeId + i;
node.Leaf = true;
nodes.Add(node);
}
nodes[0].CustomAttributes.Add(new ConfigItem("selected", "true", ParameterMode.Raw));
context.Response.Write(nodes.ToJson());
context.Response.End();
}
}