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

Logging Row data of child grid on button click

Hi Team,

I have implemented a hierarchy grid, in which the childgrid is having a Details button. On clicking that Details button I want to access information of the entire row. Can you help me with the event that I could use to capture the data of the row for which details is clicked. 

Code Sample: 



It is not capturing the current Click event.

3 Replies

DR Dhivya Rajendran Syncfusion Team August 28, 2019 12:47 PM UTC

Hi Kunal, 
 
Thanks for contacting Syncfusion support. 
 
We have validated the provided code example and you can achieve your requirement by using following way. Please refer the code example and sample for more information. 
 
[app.component.html] 
 
<ejs-grid #Grid id='Grid' (click)='click($event)' [dataSource]='parentData' [childGrid]='childGrid'> 
  <e-columns> 
    <e-column field='EmployeeID' headerText='Employee ID' width='120' textAlign='Right'></e-column> 
    <e-column field='FirstName' headerText='Name' width='140'></e-column> 
    <e-column field='Title' headerText='Title' width='170'></e-column> 
    <e-column field='HireDate' headerText='Hired Date' width='120' format='yMd' textAlign='Right'></e-column> 
    <e-column field='ReportsTo' headerText='Reports To' width='120' textAlign='Right'></e-column> 
  </e-columns> 
</ejs-grid> 
 
 
[app.component.ts] 
 
export class AppComponent { 
  . . . . . 
  click(e) { 
    // add class for the template button 
    if (e.target.classList.contains('btn')) { 
       let gridEle = parentsUntil(e.target,'e-grid'); // get current child parent element 
       let gobj = gridEle['ej2_instances'][0]; // create current child grid instance 
       // get row information 
       console.log(gobj.getRowInfo(e.target)); 
    } 
  } 
 
  ngOnInit(): void { 
    this.parentData = employeeData; 
    this.childGrid = { 
      . . . . . 
      columns: [ 
        { field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120 }, 
        { field: 'ShipCity', headerText: 'Ship City', width: 120 }, 
        { field: 'Freight', headerText: 'Freight', width: 120 }, 
        { field: 'ShipName', headerText: 'Ship Name', width: 150 }, 
        { headerText: 'Action', width: 120, template: '<div><button class="btn">Details</button></div>' } 
      ], 
 
    }; 
  } 
} 
 
 
In above example we have bind the click event for Grid and we can get current the row details from the child Grid by using getRowInfo method of Grid. 
 
 
 
Regards, 
R.Dhivya 



KB Kunal Bajaj August 29, 2019 12:36 PM UTC

Thanks a lot for the solution. Worked in a single go for me. Really appreciate your help :)



DR Dhivya Rajendran Syncfusion Team August 30, 2019 06:16 AM UTC

Hi Kunal, 
 
Thanks for your update. 
 
We are happy that the provided solution was helpful to achieve your requirement. 
 
Please get back to us if you need further assistance from us. 
 
Regards, 
R.Dhivya  


Loader.
Up arrow icon