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

[Solved] How do you format TreeView ajax data?

1 Answer 112 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.
indeynz
Top achievements
Rank 1
indeynz asked on 29 Sep 2010, 11:49 PM
We are coding an MVC TreeView and need to be able to format the child nodes adding specific attributes.
We have added our custom attributes in the root node using HtmlAttributes.Add, ("NodeType" is being added to the root node in this example), but we are unable to attach the attributes to the child nodes.

Any help would be appreciated. Thanks.

Index.aspx
<%=Html.Telerik().TreeView() 
    .Name("TreeViewUser") 
    .ShowCheckBox(true) 
    .ClientEvents(events => events 
        .OnChecked("OnClientNodeChecked")                                
    ) 
        .BindTo(UserTreeViewModel.GetDefaultTreeNodes(), (item, user) => 
        { 
            item.Text = user.Name; 
            item.Value = user.ID.ToString(); 
            item.HtmlAttributes.Add("NodeType", user.Type); 
            item.LoadOnDemand = true;  
        }) 
        .DataBinding(dataBinding => dataBinding 
            .Ajax().Select("LoadNodesMVC", "SendProfile") 
        )                                           
%>


SendProfileController.cs
[JsonParamFilter(Param = "node", TargetType = typeof(TreeViewItem))] 
public virtual JsonResult LoadNodesMVC(TreeViewItem node) 
{ 
    List<UserTreeViewModel> users = GetUsersFromSession(); 
    var nodes = from user in users 
                where user.ParentID.ToString() == node.Value 
                select new TreeViewItem() 
                { 
                    Text = user.Name, 
                    Value = user.ID.ToString(), 
                    Expanded = false
                }; 
    
    return Json(new { d = nodes.ToArray() }); 
}

1 Answer, 1 is accepted

Sort by
0
Rick
Top achievements
Rank 1
answered on 14 Oct 2010, 10:45 PM
Same problem.

The custom attribute is not being applied when Children are loaded on demand via Ajax.
Tags
TreeView
Asked by
indeynz
Top achievements
Rank 1
Answers by
Rick
Top achievements
Rank 1
Share this question
or