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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

About hierarchical bindings of grid

Thread ID:

Created:

Updated:

Platform:

Replies:

143652 Mar 30,2019 02:45 AM UTC Apr 2,2019 08:39 AM UTC ASP.NET MVC - EJ 2 3
loading
Tags: Grid
Pylori
Asked On March 30, 2019 02:48 AM UTC

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.



Pavithra Subramaniyam [Syncfusion]
Replied On April 1, 2019 04:54 AM UTC

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. 


Pylori
Replied On April 1, 2019 10:54 AM UTC

Hi Pavithra S,

Thank you for answering.
Implement using "QueryString".

Regards,
Pylori.

Pavithra Subramaniyam [Syncfusion]
Replied On April 2, 2019 08:39 AM UTC

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. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon