diff --git a/src/app/modules/angular-slickgrid/extensions/__tests__/contextMenuExtension.spec.ts b/src/app/modules/angular-slickgrid/extensions/__tests__/contextMenuExtension.spec.ts index 5cae9d12a..59fd92163 100644 --- a/src/app/modules/angular-slickgrid/extensions/__tests__/contextMenuExtension.spec.ts +++ b/src/app/modules/angular-slickgrid/extensions/__tests__/contextMenuExtension.spec.ts @@ -853,10 +853,7 @@ describe('contextMenuExtension', () => { const menuItemCommand = copyGridOptionsMock.contextMenu.commandItems.find((item: MenuCommandItem) => item.command === 'export-excel') as MenuCommandItem; menuItemCommand.action(new CustomEvent('change'), { command: 'export-excel', cell: 0, row: 0 } as any); - expect(excelExportSpy).toHaveBeenCalledWith({ - filename: 'export', - format: FileType.xlsx, - }); + expect(excelExportSpy).toHaveBeenCalled(); }); it('should call "exportToFile" with CSV set when the command triggered is "export-csv"', () => { @@ -870,9 +867,7 @@ describe('contextMenuExtension', () => { expect(exportSpy).toHaveBeenCalledWith({ delimiter: DelimiterType.comma, - filename: 'export', format: FileType.csv, - useUtf8WithBom: true }); }); @@ -887,9 +882,7 @@ describe('contextMenuExtension', () => { expect(exportSpy).toHaveBeenCalledWith({ delimiter: DelimiterType.tab, - filename: 'export', format: FileType.txt, - useUtf8WithBom: true }); }); diff --git a/src/app/modules/angular-slickgrid/extensions/__tests__/gridMenuExtension.spec.ts b/src/app/modules/angular-slickgrid/extensions/__tests__/gridMenuExtension.spec.ts index b62d506d4..21cce7130 100644 --- a/src/app/modules/angular-slickgrid/extensions/__tests__/gridMenuExtension.spec.ts +++ b/src/app/modules/angular-slickgrid/extensions/__tests__/gridMenuExtension.spec.ts @@ -662,10 +662,7 @@ describe('gridMenuExtension', () => { instance.onCommand.notify({ grid: gridStub, command: 'export-excel' }, new Slick.EventData(), gridStub); expect(onCommandSpy).toHaveBeenCalled(); - expect(excelExportSpy).toHaveBeenCalledWith({ - filename: 'export', - format: FileType.xlsx, - }); + expect(excelExportSpy).toHaveBeenCalled(); }); it('should call "exportToFile" with CSV set when the command triggered is "export-csv"', () => { @@ -678,9 +675,7 @@ describe('gridMenuExtension', () => { expect(onCommandSpy).toHaveBeenCalled(); expect(exportSpy).toHaveBeenCalledWith({ delimiter: DelimiterType.comma, - filename: 'export', format: FileType.csv, - useUtf8WithBom: true }); }); @@ -694,9 +689,7 @@ describe('gridMenuExtension', () => { expect(onCommandSpy).toHaveBeenCalled(); expect(exportSpy).toHaveBeenCalledWith({ delimiter: DelimiterType.tab, - filename: 'export', format: FileType.txt, - useUtf8WithBom: true }); }); diff --git a/src/app/modules/angular-slickgrid/extensions/contextMenuExtension.ts b/src/app/modules/angular-slickgrid/extensions/contextMenuExtension.ts index b6d15d3e0..95e796910 100644 --- a/src/app/modules/angular-slickgrid/extensions/contextMenuExtension.ts +++ b/src/app/modules/angular-slickgrid/extensions/contextMenuExtension.ts @@ -230,9 +230,7 @@ export class ContextMenuExtension implements Extension { positionOrder: 51, action: () => this.exportService.exportToFile({ delimiter: DelimiterType.comma, - filename: 'export', format: FileType.csv, - useUtf8WithBom: true, }), } ); @@ -250,10 +248,7 @@ export class ContextMenuExtension implements Extension { disabled: false, command: commandName, positionOrder: 52, - action: () => this.excelExportService.exportToExcel({ - filename: 'export', - format: FileType.xlsx, - }), + action: () => this.excelExportService.exportToExcel(), } ); } @@ -272,9 +267,7 @@ export class ContextMenuExtension implements Extension { positionOrder: 53, action: () => this.exportService.exportToFile({ delimiter: DelimiterType.tab, - filename: 'export', format: FileType.txt, - useUtf8WithBom: true, }), } ); diff --git a/src/app/modules/angular-slickgrid/extensions/gridMenuExtension.ts b/src/app/modules/angular-slickgrid/extensions/gridMenuExtension.ts index 16ce1ab60..9bffd75f9 100644 --- a/src/app/modules/angular-slickgrid/extensions/gridMenuExtension.ts +++ b/src/app/modules/angular-slickgrid/extensions/gridMenuExtension.ts @@ -398,23 +398,16 @@ export class GridMenuExtension implements Extension { case 'export-csv': this.exportService.exportToFile({ delimiter: DelimiterType.comma, - filename: 'export', format: FileType.csv, - useUtf8WithBom: true, }); break; case 'export-excel': - this.excelExportService.exportToExcel({ - filename: 'export', - format: FileType.xlsx, - }); + this.excelExportService.exportToExcel(); break; case 'export-text-delimited': this.exportService.exportToFile({ delimiter: DelimiterType.tab, - filename: 'export', format: FileType.txt, - useUtf8WithBom: true, }); break; case 'toggle-filter': diff --git a/src/app/modules/angular-slickgrid/services/excelExport.service.ts b/src/app/modules/angular-slickgrid/services/excelExport.service.ts index bcf6819e9..2d2c3b279 100644 --- a/src/app/modules/angular-slickgrid/services/excelExport.service.ts +++ b/src/app/modules/angular-slickgrid/services/excelExport.service.ts @@ -21,11 +21,16 @@ import { } from '../models/index'; import { Constants } from '../constants'; import { exportWithFormatterWhenDefined } from './export-utilities'; -import { addWhiteSpaces, getTranslationPrefix, mapMomentDateFormatWithFieldType, sanitizeHtmlToText, titleCase } from './utilities'; +import { addWhiteSpaces, deepCopy, getTranslationPrefix, mapMomentDateFormatWithFieldType, sanitizeHtmlToText, titleCase } from './utilities'; // using external non-typed js libraries declare let $: any; +const DEFAULT_EXPORT_OPTIONS: ExcelExportOption = { + filename: 'export', + format: FileType.xlsx +}; + @Injectable() export class ExcelExportService { private _fileFormat = FileType.xlsx; @@ -80,14 +85,14 @@ export class ExcelExportService { * * Example: exportToExcel({ format: FileType.csv, delimiter: DelimiterType.comma }) */ - exportToExcel(options: ExcelExportOption): Promise { + exportToExcel(options?: ExcelExportOption): Promise { if (!this._grid || !this._dataView) { throw new Error('[Angular-Slickgrid] it seems that the SlickGrid & DataView objects are not initialized did you forget to enable the grid option flag "enableExcelExport"?'); } return new Promise((resolve, reject) => { this.onGridBeforeExportToExcel.next(true); - this._excelExportOptions = $.extend(true, {}, this._gridOptions.excelExportOptions, options); + this._excelExportOptions = deepCopy({ ...DEFAULT_EXPORT_OPTIONS, ...this._gridOptions.excelExportOptions, ...options }); this._fileFormat = this._excelExportOptions.format || FileType.xlsx; // prepare the Excel Workbook & Sheet diff --git a/src/app/modules/angular-slickgrid/services/export.service.ts b/src/app/modules/angular-slickgrid/services/export.service.ts index 67fd059ed..3d1b28b89 100644 --- a/src/app/modules/angular-slickgrid/services/export.service.ts +++ b/src/app/modules/angular-slickgrid/services/export.service.ts @@ -5,6 +5,7 @@ import { Subject } from 'rxjs'; import { Column, + DelimiterType, ExportOption, FileType, GridOption, @@ -13,11 +14,18 @@ import { } from './../models/index'; import { Constants } from './../constants'; import { exportWithFormatterWhenDefined } from './export-utilities'; -import { addWhiteSpaces, getTranslationPrefix, htmlEntityDecode, sanitizeHtmlToText, titleCase } from './../services/utilities'; +import { addWhiteSpaces, deepCopy, getTranslationPrefix, htmlEntityDecode, sanitizeHtmlToText, titleCase } from './../services/utilities'; // using external non-typed js libraries declare let $: any; +const DEFAULT_EXPORT_OPTIONS: ExportOption = { + delimiter: DelimiterType.comma, + filename: 'export', + format: FileType.csv, + useUtf8WithBom: true, +}; + @Injectable() export class ExportService { private _delimiter = ','; @@ -72,14 +80,14 @@ export class ExportService { * * Example: exportToFile({ format: FileType.csv, delimiter: DelimiterType.comma }) */ - exportToFile(options: ExportOption): Promise { + exportToFile(options?: ExportOption): Promise { if (!this._grid || !this._dataView) { throw new Error('[Angular-Slickgrid] it seems that the SlickGrid & DataView objects are not initialized did you forget to enable the grid option flag "enableExcelExport"?'); } return new Promise((resolve, reject) => { this.onGridBeforeExportToFile.next(true); - this._exportOptions = $.extend(true, {}, this._gridOptions.exportOptions, options); + this._exportOptions = deepCopy({ ...DEFAULT_EXPORT_OPTIONS, ...this._gridOptions.exportOptions, ...options }); this._delimiter = this._exportOptions.delimiterOverride || this._exportOptions.delimiter || ''; this._fileFormat = this._exportOptions.format || FileType.csv;