PDA

View Full Version : [CLOSED] TreeNode load on demand



susanz
Oct 23, 2014, 5:16 PM
I want to config my tree panel to initialized with first level nodes then load children on demand. How do I pass the current node obj or other Node properties as parameter into LoadOnDemend proxy ? My current code pass nodeid only.
Thanks
-susan zhang



X.TreePanel()
.Title ("Available Members")
.Collapsed(false)
.Store(
Html.X().TreeStore()
.Proxy(
Html.X().AjaxProxy().Url(Url.Action("LoadDimChildren", "Selector"))
)
)
.Root(Model.MemberTree)
.RootVisible(false)

Controller:
public StoreResult LoadDimChildren(string node)
{
NodeCollection nodes = new Ext.Net.NodeCollection();
..
return this.Store(nodes);
}

Daniil
Oct 24, 2014, 6:10 AM
Hi @susanz,

Please use a TreeStore's Parameters. Here is an example.

View

@{
var X = Html.X();
}

<!DOCTYPE html>
<html>
<head>
<title>Ext.Net.MVC v2 Example</title>
</head>
<body>
@X.ResourceManager()

@(X.TreePanel()
.Title("Tree")
.Height(500)
.Width(200)
.Border(false)
.Store(
X.TreeStore()
.Proxy(
X.AjaxProxy().Url(Url.Action("GetChildren"))
)
.Parameters(parameters =>
{
parameters.Add(X.StoreParameter().Name("nodeText").Value("operation.node.get('text')").Mode(ParameterMode.Raw));
})
)
.Root(
X.Node().NodeID("0").Text("Root")
)
)
</body>
</html>


Controller

public ActionResult Index()
{
return this.View();
}

public StoreResult GetChildren(string node, string nodeText)
{
NodeCollection nodes = new Ext.Net.NodeCollection();

if (!string.IsNullOrEmpty(node))
{
for (int i = 1; i < 6; i++)
{
Node asyncNode = new Node();
asyncNode.Text = nodeText + "_" + node + i;
asyncNode.NodeID = node + i;
nodes.Add(asyncNode);
}

for (int i = 6; i < 11; i++)
{
Node treeNode = new Node();
treeNode.Text = nodeText + "_" + node + i;
treeNode.NodeID = node + i;
treeNode.Leaf = true;
nodes.Add(treeNode);
}
}

return this.Store(nodes);
}

susanz
Oct 24, 2014, 4:41 PM
That works. Thank you!
-szhang