SmartCoder
SmartCoder

Reputation: 11

How to specify the default filename for exported file while exporting through the export context menu in ag grid

I tried setting the gridOptions of the grid like below. But while exporting the data through the export excel context menu, the file name is not considered. How can i set the file name while exporting the data through the export context menu of grid.

    defaultExportParams: { fileName: "TestFileName" }

Upvotes: 1

Views: 5503

Answers (1)

bensonissac
bensonissac

Reputation: 695

Try this code:

   exportCsv() {       
    var excelParams = {
        columnKeys: ['firstName', 'middleName','lastName', 'dob'],
        allColumns: false,
        fileName: 'Student List.csv',
        skipHeader: false,
        customHeader: 'Student List' + '\n',
        customFooter: '\n \n Total No.Of Students :' + this.gridOptions.api.getModel().getRowCount() + ' \n'
    }
    this.gridOptions.api.exportDataAsCsv(excelParams);
}

Upvotes: 3

Related Questions