Skip to content

Commit a4e8f73

Browse files
prx-lmomportuga
authored andcommitted
[hotfix/4446]
- exporterExcelFileName and SheetName are now possible to be functions
1 parent 0e58afb commit a4e8f73

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

packages/exporter/src/js/exporter.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,13 @@
262262
* @propertyOf ui.grid.exporter.api:GridOptions
263263
* @description The default filename to use when saving the downloaded excel, only used in IE (other browsers open excels in a new window)
264264
* <br/>Defaults to 'download.xlsx'
265+
* <pre>
266+
* gridOptions.exporterExcelFilename = "rows.xlsx"
267+
* </pre>
268+
* <br/>Or a function returning a string:
269+
* <pre>
270+
* gridOptions.exporterExcelFilename = function(grid, rowTypes, colTypes) { return "rows" + rowTypes + ".xlsx" };
271+
* </pre>
265272
*/
266273
gridOptions.exporterExcelFilename = gridOptions.exporterExcelFilename ? gridOptions.exporterExcelFilename : 'download.xlsx';
267274

@@ -271,6 +278,13 @@
271278
* @propertyOf ui.grid.exporter.api:GridOptions
272279
* @description The default sheetname to use when saving the downloaded to excel
273280
* <br/>Defaults to 'Sheet1'
281+
* <pre>
282+
* gridOptions.exporterExcelSheetName = "HitListSheet"
283+
* </pre>
284+
* <br/>Or a function returning a string:
285+
* <pre>
286+
* gridOptions.exporterExcelSheetName = function(grid, rowTypes, colTypes) { return "HitListSheet" + rowTypes };
287+
* </pre>
274288
*/
275289
gridOptions.exporterExcelSheetName = gridOptions.exporterExcelSheetName ? gridOptions.exporterExcelSheetName : 'Sheet1';
276290

@@ -1624,9 +1638,13 @@
16241638
this.loadAllDataIfNeeded(grid, rowTypes, colTypes).then(function() {
16251639
var exportColumnHeaders = grid.options.showHeader ? self.getColumnHeaders(grid, colTypes) : [];
16261640

1627-
var workbook = new ExcelBuilder.Workbook();
1628-
var aName = grid.options.exporterExcelSheetName ? grid.options.exporterExcelSheetName : 'Sheet1';
1641+
var aName = 'Sheet1';
1642+
if (grid.options.exporterExcelSheetName) {
1643+
aName = angular.isFunction(grid.options.exporterExcelSheetName) ? grid.options.exporterExcelSheetName(grid, rowTypes, colTypes) : grid.options.exporterExcelSheetName;
1644+
}
1645+
16291646
var sheet = new ExcelBuilder.Worksheet({name: aName});
1647+
var workbook = new ExcelBuilder.Workbook();
16301648
workbook.addWorksheet(sheet);
16311649
var docDefinition = self.prepareAsExcel(grid, workbook, sheet);
16321650

@@ -1649,8 +1667,8 @@
16491667
sheet.setData(sheet.data.concat(excelContent));
16501668

16511669
ExcelBuilder.Builder.createFile(workbook, {type: 'blob'}).then(function(result) {
1652-
self.downloadFile (grid.options.exporterExcelFilename, result, grid.options.exporterCsvColumnSeparator,
1653-
grid.options.exporterOlderExcelCompatibility);
1670+
var fileName = angular.isFunction(grid.options.exporterExcelFilename) ? grid.options.exporterExcelFilename(grid, rowTypes, colTypes) : grid.options.exporterExcelFilename;
1671+
self.downloadFile(fileName, result, grid.options.exporterCsvColumnSeparator, grid.options.exporterOlderExcelCompatibility);
16541672
});
16551673
});
16561674
}

0 commit comments

Comments
 (0)