This question is locked. New answers and comments are not allowed.
Hello, I have a complex TreeView and I need to put a 'LoadOnDemand' functionality in place.. Could you please help me with the syntax a bit ?
Here is what I did, but in the debug mode Ajax method does not get hit..
VIEW:
Html.Telerik().TreeView()
.Name("HierarchyView")
.ClientEvents(events => events
.OnCollapse("updateTreeViewState")
.OnExpand("updateTreeViewState"))
.BindTo(Model, mappings =>
{
mappings.For<Division>(binding => binding
.ItemDataBound((item, branch) =>
{
item.Text = branch.Name;
item.Expanded = ((string[])ViewData["ExpandedNodes"]).Contains(item.Text);
item.LoadOnDemand = true;
})
.Children(branch => branch.Branches)
);
mappings.For<Region>(binding => binding
.ItemDataBound((item, branch) =>
{
item.Text = branch.Name;
item.Expanded = ((string[])ViewData["ExpandedNodes"]).Contains(item.Text);
item.LoadOnDemand = true;
})
.Children(branch => branch.Branches)
);
mappings.For<ProfitCentre>(binding => binding
.ItemDataBound((item, branch) =>
{
item.Text = branch.Name;
item.Expanded = ((string[])ViewData["ExpandedNodes"]).Contains(item.Text);
item.LoadOnDemand = true;
})
.Children(branch => branch.RMs)
);
mappings.For<User>(binding => binding
.ItemDataBound((item, rm) =>
{
item.Url = Url.Action("StartBrowseAs", "Account", new {rmId = rm.Id});
item.Text = rm.FullName;
item.Value = rm.FullName;
item.Expanded = ((string[])ViewData["ExpandedNodes"]).Contains(item.Url);
item.Content = () =>{ Html.RenderPartial("~/Views/Account/TreeMenu.ascx", rm);};
})
.Children(user => null)
);
})
.DataBinding(dataBinding => dataBinding
.Ajax().Select("_AjaxGetSubordinateTreeView", "Account"))
.Render();
CONTROLLER:
[HttpGet]
public ActionResult GetSubordinateTreeView()
{
IEnumerable<HierarchyElement> branches = null;
.. // populate 'branches'
return PartialView("SubordinateTreeView", branches);
}
[HttpPost]
public ActionResult _AjaxGetSubordinateTreeView(TreeViewItemModel node)
{
IEnumerable<HierarchyElement> branches = null;
... // populate 'branches'
return new JsonResult { Data = branches };
}
Here is what I did, but in the debug mode Ajax method does not get hit..
VIEW:
Html.Telerik().TreeView()
.Name("HierarchyView")
.ClientEvents(events => events
.OnCollapse("updateTreeViewState")
.OnExpand("updateTreeViewState"))
.BindTo(Model, mappings =>
{
mappings.For<Division>(binding => binding
.ItemDataBound((item, branch) =>
{
item.Text = branch.Name;
item.Expanded = ((string[])ViewData["ExpandedNodes"]).Contains(item.Text);
item.LoadOnDemand = true;
})
.Children(branch => branch.Branches)
);
mappings.For<Region>(binding => binding
.ItemDataBound((item, branch) =>
{
item.Text = branch.Name;
item.Expanded = ((string[])ViewData["ExpandedNodes"]).Contains(item.Text);
item.LoadOnDemand = true;
})
.Children(branch => branch.Branches)
);
mappings.For<ProfitCentre>(binding => binding
.ItemDataBound((item, branch) =>
{
item.Text = branch.Name;
item.Expanded = ((string[])ViewData["ExpandedNodes"]).Contains(item.Text);
item.LoadOnDemand = true;
})
.Children(branch => branch.RMs)
);
mappings.For<User>(binding => binding
.ItemDataBound((item, rm) =>
{
item.Url = Url.Action("StartBrowseAs", "Account", new {rmId = rm.Id});
item.Text = rm.FullName;
item.Value = rm.FullName;
item.Expanded = ((string[])ViewData["ExpandedNodes"]).Contains(item.Url);
item.Content = () =>{ Html.RenderPartial("~/Views/Account/TreeMenu.ascx", rm);};
})
.Children(user => null)
);
})
.DataBinding(dataBinding => dataBinding
.Ajax().Select("_AjaxGetSubordinateTreeView", "Account"))
.Render();
CONTROLLER:
[HttpGet]
public ActionResult GetSubordinateTreeView()
{
IEnumerable<HierarchyElement> branches = null;
.. // populate 'branches'
return PartialView("SubordinateTreeView", branches);
}
[HttpPost]
public ActionResult _AjaxGetSubordinateTreeView(TreeViewItemModel node)
{
IEnumerable<HierarchyElement> branches = null;
... // populate 'branches'
return new JsonResult { Data = branches };
}