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

get grid instance from toolbarClick

Hi,

I've 3 grids in component.

How can I get the grid instance in toolbarClick.

I need some similar at this

toolbarClick(args: ClickEventArgs): void {
const grid: GridComponent;
grid = args.item.controlParent;
switch (args.item.text) {
case 'PDF Export':
grid.pdfExport();
break;
case 'Excel Export':
gridResumen.excelExport();
break;
case 'CSV Export':
grid.csvExport();
break;
}
}


But grid variable, is not GridComponent

5 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team November 29, 2018 04:54 AM UTC

Hi Manolo, 

Thanks for contacting Syncfusion support. 

You can get the grid instances from the ‘this.grid’ parameter in the toolbarClick event of Grid. 

Refer the help documentation. 



Regards, 
Thavasianand S. 



MC Manolo Capdevila November 29, 2018 11:08 AM UTC

Hi,

With this.grid I need save the grid reference in grid vairable.

My question is if, since ClickEventArgs, I can get the grid reference for export.


I've three different grids, so if in toolbarClick function, I can get the grid instance, I don't need save each grid reference in different variables

Thanks


MS Madhu Sudhanan P Syncfusion Team November 30, 2018 06:22 AM UTC

Hi Manolo,  

Thanks for contacting Syncfusion support. 

You can use the same event handler for multiple grid by passing the template variable as the argument of the event as follows. 


    <ejs-grid #grid (toolbarClick)='toolbarClick($event, grid)' [allowExcelExport]='true' [allowPdfExport]='true' > 
        ... 
    </ejs-grid> 
 
    <ejs-grid #grid5 (toolbarClick)='toolbarClick($event, grid5)' 
                [allowExcelExport]='true' [allowPdfExport]='true'> 
       ... 
    </ejs-grid> 


export class ExportingComponent implements OnInit { 
  ... 
  toolbarClick(args: ClickEventArgs, grid: GridComponent): void { 
      switch (args.item.text) { 
          case 'PDF Export': 
              grid.pdfExport(); 
              break; 
          ... 
      } 
  } 
} 





Regards,  
Madhu Sudhanan P


MC Manolo Capdevila November 30, 2018 01:28 PM UTC

Thanks!


TS Thavasianand Sankaranarayanan Syncfusion Team December 3, 2018 05:26 AM UTC

Hi Manolo, 
 
We are happy that the problem has been solved. 
 
Please get back to us if you need any further assistance.  
                          
Regards, 
Thavasianand S.                         


Loader.
Live Chat Icon For mobile
Up arrow icon