We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

About hierarchical bindings of grid

Hi,


Is it possible to do hierarchical binding easily without using "QueryString" for parent-child relationship view models as follows?


class ParentViewModel
{
    public string ParentName { get; set; }
    public List<ChildViewModel> Children { get; set; }
}

class ChildViewModel
{
    public string ChildName { get; set; }
}


Regards,
Pylori.



3 Replies

PS Pavithra Subramaniyam Syncfusion Team March 31, 2019 08:54 PM

Hi Pylori, 
 
Thanks for contacting Syncfusion support.  
 
Query : Is it possible to do hierarchical binding easily without using "QueryString" for parent-child relationship view models as follows? 
 
No, The child Grid is bounded to the Parent row based on the “queryString” relation only. So defining the ‘queryString’ property is essential for the Hierarchical Binding feature. 
 
Regards, 
Pavithra S. 



PY Pylori April 1, 2019 02:54 AM

Hi Pavithra S,

Thank you for answering.
Implement using "QueryString".

Regards,
Pylori.


PS Pavithra Subramaniyam Syncfusion Team April 2, 2019 12:39 AM

Hi Pylori, 
 
Thanks for the update. 
 
We would like to explain the “Hierarchical binding in Grid”. The Grid will display as a hierarchy(parent-child) when the dataSource of the parent and child Grid have a common “field” name(which will be used as the value for “QueryString”), and by comparing the values of this field name, the child Grid will be displayed.  
 
Based on the shared model, we have prepared a sample by binding same dataSource for both child and parent Grids. We have achieved this requirement by using the “created” event of Child Grid. Please refer the code example and sample link below, 
 
 
[Index.cshtml] 
 
<div> 
    @Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.datasource).AllowPaging().Columns(col => 
        { 
             ... 
        })...Load("load").Render() 
</div> 
 
<script> 
    var data = @Html.Raw(Json.Encode(ViewBag.datasource)); 
    function load(args) { 
        var grid = document.getElementById('Grid').ej2_instances[0] 
       grid.childGrid = { 
            dataSource: data, 
            queryString: 'EmployeeID', 
            created:created, 
            ... 
       } 
    } 
    function created(args) { 
        this.dataSource = this.parentDetails.parentRowData.Employee;          //Bind the data to Child Grid 
    } 
</script> 
 
 
Documentations :  
 
Please get back to us if you need further assistance. 
 
Regards, 
Pavithra S. 


Loader.
Live Chat Icon For mobile
Up arrow icon