Complex Data Binding in ASP.NET MVC Tree Grid Component

21 Dec 20221 minute to read

You can achieve complex data binding in the treegrid by using the dot(.) operator in the Field in Column.

@using Syncfusion.EJ2.Grids

@(Html.EJS().TreeGrid("ComplexBinding").DataSource((IEnumerable<object>)ViewBag.datasource)
            .Columns(col =>
             {
               col.Field("taskID").HeaderText("Task ID").Width(90).TextAlign(TextAlign.Right).Add();
               col.Field("taskName").HeaderText("Task Name").Width(180).Add();
               col.Field("assignee.firstname").HeaderText("Duration").Width(90).TextAlign(TextAlign.Right).Add();
               col.Field("duration").HeaderText("Duration").Width(80).TextAlign(TextAlign.Right).Add();

             }).Height(315).ChildMapping("Children").TreeColumnIndex(1).Render()
)
public ActionResult ComplexBinding()
{
    var treeData = TreeGridItems.GetTreeData();
    ViewBag.datasource = treeData;
    return View();    
}

NOTE

You can refer to our ASP.NET MVC Tree Grid feature tour page for its groundbreaking feature representations. You can also explore our ASP.NET MVC Tree Grid example to knows how to present and manipulate data.