Custom Excel export error

Hello.

I have problem with grid component. I have created the context menu for excel export, and after row is clicked and selected i need to get data for that one particular row and export data for it.
But when i export it i got two Excel files. One with table data and second is with row data.

I don't need first file with grid data.

How to can i do that? 
Here is code:

TS:

  contextMenuClick(args: MenuEventArgs): void {
    if (args.item.id == 'workhours_grid_cmenu_ExcelExport' && args.rowInfo) {      
       this.workhoursService.getWorklogByEID(args.rowInfo.rowData.employee_id,this.worklogName ).subscribe(data => {
         data.forEach(element => {
          let date_F = element.date_from ==null? null : element.date_from.split('T')[0];
          let time_F = element.date_from ==null? null : element.date_from.split('T')[1];
          element.date_from = date_F + " - " + time_F.substring(0,5);
          let date_T = element.date_to ==null? null : element.date_to.split('T')[0];
          let time_T = element.date_to ==null? null : element.date_to.split('T')[1];
          element.date_to = date_T + " - " + time_T.substring(0,5);          
         });      
          const CustomExcelExportProperties: ExcelExportProperties = {
            dataSource: data,
            columns:[            
              {field:'date_from',headerText:'FROM', width:'200px'}  as any,
              {field:'date_to',headerText:'TO', width:'200px'},
              {field:'duration',headerText:'DURATION', width:'100px'},
              {field:'total_hr_regular',headerText:'TOTAL HR', width:'100px'},
              {field:'description',headerText:'DESCRIPTION', width:'500px'}
            ]
          };  
          this.Grid.excelExport(CustomExcelExportProperties);          
      });    
    }
}

1 Reply

PS Pavithra Subramaniyam Syncfusion Team April 4, 2022 10:12 AM UTC

Hi Emir,


Thanks for contacting Syncfusion support.


Since you have called the grid excelExport method inside the contextMenuClick event, both default and sample side call invoke the Excel export action. So, you need to add a custom context menu item to achieve your requirement. Please refer to the below code example, documentation, and sample link for more information.


export class AppComponent {

 

  ngOnInit(): void {

    this.contextMenuItems = [

      .  .  .

      { text: 'Excel_Exporting', target: '.e-content', id: 'export' },

    ];

  }

  contextMenuClick(args: MenuEventArgs): void {

    if (args.item.id == 'export' && args.rowInfo) {

      this.workhoursService.getWorklogByEID(args.rowInfo.rowData.employee_id, this.worklogName).subscribe(data => {

         .  .  .

        this.Grid.excelExport(CustomExcelExportProperties);

      });

    }

  }

}

 


Documentation : https://ej2.syncfusion.com/angular/documentation/grid/context-menu/#custom-context-menu-items


Sample               : https://stackblitz.com/edit/angular-b7fzja?file=app.component.ts


Please get back to us if you need further assistance on this.


Regards,

Pavithra S


Loader.
Up arrow icon