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

Will Hierarchy grid works for many to many associated data

I had many to many associated table sample data will be like the below sample,

I need to show company details as the parent and employee details as the child.

Also i need to edit the employee details, 

I have tried the Hierarchy grid MVC Syncfusion EJS 1, But it the field name provided in querystring need to be in the child data, In Many to Many associated data it won't have. 

Please suggest me any to get it work.


[
  {
    "companyId": "1",
    "name": "ACME, SL",
    "employees": "50",
    "contacts": [
      {
        "employeeId": "1",
        "name": "John",
        "surename": "Smith",
        "department": "Finanzes"
      },
      {
        "employeeId": "2",
        "name": "Alex",
        "surename": "Sanchez",
        "department": "Support"
      },
      {
        "employeeId": "3",
        "name": "Carmen",
        "surename": "Calvo",
        "department": "Finanzes"
      }
    ]
  },
  {
    "companyId": "2",
    "name": "Trendsuper Inc.",
    "employees": "30",
    "contacts": [
      {
        "employeeId": "1",
        "name": "John",
        "surename": "Smith",
        "department": "Finanzes"
      },
      {
        "employeeId": "2",
        "name": "Alex",
        "surename": "Sanchez",
        "department": "Support"
      },
      {
        "employeeId": "3",
        "name": "Carmen",
        "surename": "Calvo",
        "department": "Finanzes"
      },
      {
        "employeeId": "4",
        "name": "John",
        "surename": "Wartong",
        "department": "Labs"
      },
      {
        "employeeId": "5",
        "name": "Quentin",
        "surename": "Tarantino",
        "department": "Support"
      },
      {
        "employeeId": "6",
        "name": "Josh",
        "surename": "Sheldon",
        "department": "IT"
      }
    ]
  },
  {
    "companyId": "3",
    "name": "Cacatua Inc.",
    "employees": "10",
    "contacts": [
       {
        "employeeId": "4",
        "name": "John",
        "surename": "Wartong",
        "department": "Labs"
      },
      {
        "employeeId": "5",
        "name": "Quentin",
        "surename": "Tarantino",
        "department": "Support"
      },
      {
        "employeeId": "6",
        "name": "Josh",
        "surename": "Sheldon",
        "department": "IT"
      },
      {
        "employeeId": "8",
        "name": "Walter",
        "surename": "Distey",
        "department": "Labs"
      },
      {
        "employeeId": "9",
        "name": "Quentin",
        "surename": "Danubio",
        "department": "Support"
      }
    ]
  }
]

1 Reply

HJ Hariharan J V Syncfusion Team May 14, 2019 01:19 PM UTC

Hi Saivikki, 
  
Thanks for contacting Syncfusion support, 
  
We have prepared sample based on your requirement. We have achieved your requirement using “Created”, “dataBound”,”detailDataBound” events of the EJ2 Grid. Please find the below code snippet and Sample documentation links for your reference.  
  
@{  
    var ChildGrid1 = new Syncfusion.EJ2.Grids.Grid()  
    {  
        DataSource = ViewBag.empData,  
        QueryString = "EmployeeID",  
        Created ="created",  
        DataBound="dataBound",  
         . . .  
 
  
    };  
        }  
  
<ejs-grid id="PublishedGrid" dataSource="ViewBag.data" childGrid="ChildGrid1" detailDataBound="detailDataBound" allowPaging="true" >  
    . . .  
</ejs-grid>  
<script>  
    var val;  
    var flag = 1;  
    function detailDataBound(args) {  
        val = args.data;    
    }  
    function created(args) {  
        flag = 1;  
    }  
    function dataBound(args) {  
        if (flag) {  
            var pre = [];  
  
           // You can handle many unique columns(querystring) in Child Grid 
            pre.push(new ej.data.Predicate('EmployeeID', 'equal', val["EmployeeID"]));  
            pre.push(new ej.data.Predicate('orderid', 'equal', val["OrderID"]));  
            this.query = new ej.data.Query().where(new ej.data.Predicate.and(pre));  
            this.refresh();  
            flag = 0;  
        }  
      
    }  
</script>  


 
  
                                         https://ej2.syncfusion.com/documentation/api/grid/#databound  
                                         https://ej2.syncfusion.com/documentation/api/grid/#detaildatabound  
  
Please get back to us if you need further assistance.  
  
Regards, 
Hariharan 


Loader.
Live Chat Icon For mobile
Up arrow icon