Skip to content

Setting custom excelExportOptions.filename is not working for excelExport  #655

Closed
@chitwank-asu

Description

@chitwank-asu

I'm submitting a Bug report

Your Environment

Software Version(s)
Angular 11.0.4
Angular-Slickgrid 2.24.1
TypeScript 4.0.2

Describe the Bug

Steps to Reproduce

  1. set gridoptions.excelExportOptions.filename = 'customName';;
 this.gridOptions = {
      enableAutoResize: true,
      enableExcelExport: true,
      excelExportOptions: {
        filename: 'PurchaseOrders',
        exportWithFormatter: true
      }, ....
}
  1. Click on the default export to excel from context menu, downloaded file name still showing 'export'
  2. Same thing, when we click on Export to excel from the hamburger menu, downloaded file name still showing 'export'

Expected Behavior

When we set custom filename in excelExportOptions, and click on Export to excel from context menu or hamburger menu, the downloaded file name should be the custom name that is being set.

Current Behavior

  1. Clicking on the default export to excel from context menu, downloaded file name still showing 'export'
  2. Same thing, when we click on Export to excel from the hamburger menu, downloaded file name still showing 'export'

Possible Solution

It seems to be happening because there is a hardcoded file name as export , (where as it should be picking the name from exportoptions is it is set there by the user)in angular-sclickgrid.js file file in executeGridMenuInternalCustomCommands() method for below:

  case 'export-excel':
                    this.excelExportService.exportToExcel({
                        **filename: 'export',**
                        format: FileType.xlsx,
                    });

and also is there for the context menu click method too:

  // show context menu: Export to Excel
        if (gridOptions && gridOptions.enableExcelExport && contextMenu && !contextMenu.hideExportExcelCommand) {
            const commandName = 'export-excel';
            if (!originalCustomItems.find((item) => item.hasOwnProperty('command') && item.command === commandName)) {
                menuCustomItems.push({
                    iconCssClass: contextMenu.iconExportExcelCommand || 'fa fa-file-excel-o text-success',
                    title: this.extensionUtility.translateWhenEnabledAndServiceExist(`${translationPrefix}EXPORT_TO_EXCEL`, 'TEXT_EXPORT_TO_EXCEL'),
                    disabled: false,
                    command: commandName,
                    positionOrder: 52,
                    action: () => this.excelExportService.exportToExcel({
                        **filename: 'export',**
                        format: FileType.xlsx,
                    }),
                });
            }

Code Sample

this.gridOptions = {
      enableAutoResize: true,
      enableExcelExport: true,
      excelExportOptions: {
        filename: 'PurchaseOrders',
        exportWithFormatter: true
      },
      datasetIdPropertyName: 'Id',
      autoResize: {
        containerId: 'demo-container',
        sidePadding: 10
      },
      enableFiltering: true,
      enableCheckboxSelector: true,
      checkboxSelector: {
        hideInFilterHeaderRow: false,
        hideInColumnTitleRow: true
      },
      enableRowSelection: true,
      pagination: {
        pageSizes: [10, 15, 20, 25, 30, 40, 50, 75, 100],
        pageSize: defaultPageSize,
        totalItems: 0
      },
      presets: {
        pagination: { pageNumber: 1, pageSize: 20 }
      },
      backendServiceApi: {
        service: new GridOdataService(),
        options: {
          enableCount: this.isCountEnabled,
          version: this.odataVersion
        } as OdataOption,
        preProcess: () => this.displaySpinner(true),
        process: (query) => this.getPurchaseOrderApiCall(query),
        postProcess: (response) => {
          this.displaySpinner(false);
          this.getPurchaseOrderCallback(response);
        }
      }
    };
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions