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

How to bind this context to child grid

Hi,
is there any way to bind 'this' context of my component to child grid?

Example - I've got code for parent grid defined on TypeScript side like this: 

private childGrid: ChildGrid = {
     editSettings: { /*someSettings*/ },
     actionComplete (args: any) {
          // here I want to have 'this' context of my component to save data when this event triggers
     }
     /* more config */
}

Hopefully, you can understand what I want to achieve.

1 Reply

TS Thavasianand Sankaranarayanan Syncfusion Team May 28, 2019 12:47 PM UTC

Hi James,  

Thanks for contacting Syncfusion support  

Query: “is there any way to bind 'this' context of my component to child grid? 

From your query, we suspect that you want to get the parent Grid details (component instance) inside the childGrid actionComplete event. We have achieved your requirement by binding the this argument along with actionComplete event. Refer the below code example 

    <ejs-grid #Grid id='Grid' [dataSource]='parentData' [childGrid]='childGrid'> 
        <e-columns> 
…………………………………………. 
        </e-columns> 
    </ejs-grid> 
 
…………………………………………… 
 
export class AppComponent { 
    @ViewChild('Grid') 
    public appGrid: GridComponent; 
      public parentData: Object[]; 
      public childGrid: any; 
      public secondChildGrid: any; 
   
   
      ngOnInit(): void { 
          this.parentData = employeeData;        
          this.childGrid = { 
              dataSource: orderDatas, 
              queryString: 'EmployeeID', 
              allowPaging: true, 
              actionComplete: onComplete.bind(this), 
              editSettings: {allowEditing: true}, 
              pageSettings: {pageSize: 6, pageCount: 5}, 
              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 } 
              ]            
          }; 
      } 
  } 
  function onComplete(args){ 
    let proxy  = this // this reutns appcomponent instance 
    this.appGrid; //here you can get the parent Grid instance.  
  } 


For your convenience we have prepared a sample which can be referred below  


Please get back to us if above solution did not match your requirement  

Regards, 
Thavasianand S.  


Loader.
Live Chat Icon For mobile
Up arrow icon