Skip to content

Commit

Permalink
fix(exporter.js): Eliminate selection column. Add export scale factor…
Browse files Browse the repository at this point in the history
… for excel and fonts

* fix(Export): Eliminate selection column. Add export scale factor for excel and fonts

* fix(Excel Export): Add doc to show in API manual

* docs(Excel export): Better doc for export to excel methods

* doc(Excel export): Fix unit tests for new api doc

* doc(Excel export): Fix unit tests for new api doc
  • Loading branch information
monster910 authored and mportuga committed Apr 23, 2018
1 parent 651f307 commit d96f43d
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 3 deletions.
78 changes: 78 additions & 0 deletions src/features/exporter/js/exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,24 @@
* <br/>Defaults to 'download.pdf'
*/
gridOptions.exporterPdfFilename = gridOptions.exporterPdfFilename ? gridOptions.exporterPdfFilename : 'download.pdf';
/**
* @ngdoc object
* @name exporterExcelFilename
* @propertyOf ui.grid.exporter.api:GridOptions
* @description The default filename to use when saving the downloaded excel, only used in IE (other browsers open excels in a new window)
* <br/>Defaults to 'download.xlsx'
*/
gridOptions.exporterExcelFilename = gridOptions.exporterExcelFilename ? gridOptions.exporterExcelFilename : 'download.xlsx';

/**
* @ngdoc object
* @name exporterExcelSheetName
* @propertyOf ui.grid.exporter.api:GridOptions
* @description The default sheetname to use when saving the downloaded to excel
* <br/>Defaults to 'Sheet1'
*/
gridOptions.exporterExcelSheetName = gridOptions.exporterExcelSheetName ? gridOptions.exporterExcelSheetName : 'Sheet1';

/**
* @ngdoc object
* @name exporterOlderExcelCompatibility
Expand Down Expand Up @@ -560,6 +578,66 @@
*/
gridOptions.exporterFieldFormatCallback = gridOptions.exporterFieldFormatCallback ? gridOptions.exporterFieldFormatCallback : function( grid, row, col, value ) { return null; };

/**
* @ngdoc function
* @name exporterExcelCustomFormatters
* @propertyOf ui.grid.exporter.api:GridOptions
* @description A function to call to setup formatters and store on docDefinition.
*
* The method is called at the start and can setup all the formatters to export to excel
*
* @param {Grid} grid provides the grid in case you have need of it
* @param {Workbook} row the row from which the data comes
* @param {docDefinition} The docDefinition that will have styles as a object to store formatters
* @returns {docDefinition} Updated docDefinition with formatter styles
*
* @example
* <pre>
* gridOptions.exporterExcelCustomFormatters = function(grid, workbook, docDefinition) {
* const formatters = {};
* const stylesheet = workbook.getStyleSheet();
* const headerFormatDefn = {
* 'font': { 'size': 11, 'fontName': 'Calibri', 'bold': true },
* 'alignment': { 'wrapText': false }
* };
*
* formatters['header'] = headerFormatter;
* Object.assign(docDefinition.styles , formatters);
* grid.docDefinition = docDefinition;
* return docDefinition;
* }
* </pre>
*/
gridOptions.exporterExcelCustomFormatters = gridOptions.exporterExcelCustomFormatters ? gridOptions.exporterExcelCustomFormatters : function( grid, workbook, docDefinition ) { return null; };

/**
* @ngdoc function
* @name exporterExcelHeader
* @propertyOf ui.grid.exporter.api:GridOptions
* @description A function to write formatted header data to sheet.
*
* The method is called to provide custom header building for Excel. This data comes before the grid header
*
* @param {grid} grid provides the grid in case you have need of it
* @param {Workbook} row the row from which the data comes
* @param {Sheet} the sheet to insert data
* @param {docDefinition} The docDefinition that will have styles as a object to store formatters
* @returns {docDefinition} Updated docDefinition with formatter styles
*
* @example
* <pre>
* gridOptions.exporterExcelCustomFormatters = function (grid, workbook, sheet, docDefinition) {
* const headerFormatter = docDefinition.styles['header'];
* let cols = [];
* // push data in A1 cell with metadata formatter
* cols.push({ value: 'Summary Report', metadata: {style: headerFormatter.id} });
* sheet.data.push(cols);
* }
* </pre>
*/
gridOptions.exporterExcelHeader = gridOptions.exporterExcelHeader ? gridOptions.exporterExcelHeader : function( grid, workbook, sheet, docDefinition ) { return null; };


/**
* @ngdoc object
* @name exporterColumnScaleFactor
Expand Down
14 changes: 11 additions & 3 deletions src/features/exporter/test/exporter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ describe('ui.grid.exporter', function() {
exporterCsvColumnSeparator: ',',
exporterCsvFilename: 'download.csv',
exporterPdfFilename: 'download.pdf',
exporterExcelFilename: 'download.xlsx',
exporterExcelSheetName: 'Sheet1',
exporterOlderExcelCompatibility: false,
exporterIsExcelCompatible: false,
exporterPdfDefaultStyle: {fontSize: 11},
Expand All @@ -150,10 +152,12 @@ describe('ui.grid.exporter', function() {
exporterMenuExcel: true,
exporterFieldCallback: jasmine.any(Function),
exporterFieldFormatCallback: jasmine.any(Function),
exporterExcelCustomFormatters: jasmine.any(Function),
exporterExcelHeader: jasmine.any(Function),
exporterColumnScaleFactor: 3.5,
exporterFieldApplyFilters: false,
exporterAllDataFn: null,
exporterSuppressColumns: [],
exporterColumnScaleFactor: 3.5,
exporterMenuItemOrder: 200
});
});
Expand All @@ -174,6 +178,8 @@ describe('ui.grid.exporter', function() {
exporterCsvColumnSeparator: ',',
exporterCsvFilename: 'download.csv',
exporterPdfFilename: 'download.pdf',
exporterExcelFilename: 'download.xlsx',
exporterExcelSheetName: 'Sheet1',
exporterOlderExcelCompatibility: false,
exporterIsExcelCompatible: false,
exporterPdfDefaultStyle : { fontSize : 11 },
Expand All @@ -194,10 +200,12 @@ describe('ui.grid.exporter', function() {
exporterMenuExcel: true,
exporterFieldCallback: jasmine.any(Function),
exporterFieldFormatCallback: jasmine.any(Function),
exporterExcelCustomFormatters: jasmine.any(Function),
exporterExcelHeader: jasmine.any(Function),
exporterColumnScaleFactor: 3.5,
exporterFieldApplyFilters: false,
exporterAllDataFn: null,
exporterSuppressColumns: [],
exporterColumnScaleFactor: 3.5,
exporterMenuItemOrder: 200
});
});
Expand Down Expand Up @@ -231,10 +239,10 @@ describe('ui.grid.exporter', function() {
exporterMenuExcel: false,
exporterFieldCallback: callback,
exporterFieldFormatCallback: callback,
exporterExcelCustomFormatters: callback,
exporterFieldApplyFilters: false,
exporterAllDataPromise: callback,
exporterSuppressColumns: [ 'buttons' ],
exporterExcelCustomFormatters: callback,
exporterExcelFilename: 'myFile.xlsx',
exporterExcelSheetName: 'Sheet1',
exporterExcelHeader: 'My Header',
Expand Down

0 comments on commit d96f43d

Please sign in to comment.