This is a migrated thread and some comments may be shown as answers.

[Solved] Load Child node on demand

1 Answer 51 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Matt
Top achievements
Rank 1
Matt asked on 20 Sep 2012, 06:22 PM

Is there a way to load a child nodes children on demand?  The http://demos.telerik.com/aspnet-mvc/razor/treeview/ajaxloading doesnt help me because its loading the first node on demand and also all of that nodes children.  The last sibling is the only node I want to load on demand

Here is my current code that works. The code is commented with the changes I would like to make but cant figure out how to.

@(Html.Telerik().TreeView()
    .Name("ImageDetailTreeView")
    .BindTo(Model.OrderDetails, mappings =>
        {
            //bind initial order data
            mappings.For<ImageViewer.Models.UI.UIModelImageDetail.OrderDetail>(binding => binding
                .ItemDataBound((item, order) =>
                {
                    item.Text = "Order Number: " + order.OrderNumber;
                })
                .Children(cat => cat.Categories));
            mappings.For<ImageViewer.Models.UI.UIModelImageDetail.CategoryDetail>(binding => binding
                .ItemDataBound((item, cat) =>
                {
                    item.Text = "Category: " + cat.Category;
                })
                .Children(tsk => tsk.Tasks));
            mappings.For<ImageViewer.Models.UI.UIModelImageDetail.TaskDetail>(binding => binding
               .ItemDataBound((item, tsk) =>
               {
                   item.Text = "Task: " + tsk.TaskName;
                   //I want this nodes children to load on deman
                   item.LoadOnDemand = true;
               })
               .Children(img => img.ImageDetails));
  
            //I would like to load this content on demand.  I cant seem to figure out how to use the BindTo
            mappings.For<ImageViewer.Models.UI.UIModelImageDetail.ImageDetail>(binding => binding
                .ItemDataBound((item, img) => 
                {
                    item.Text = "Image Id: " + img.Id + " Scan Date: " + img.ScanDate;
                })
            );
        })
)

Thanks,
Adam

1 Answer, 1 is accepted

Sort by
0
Matt
Top achievements
Rank 1
answered on 21 Sep 2012, 05:33 PM
I have come up with the solution using ajax calls to the server that return the nodes to add.  I will post how I did it when its finished and more polished.
Tags
TreeView
Asked by
Matt
Top achievements
Rank 1
Answers by
Matt
Top achievements
Rank 1
Share this question
or