Skip to content

Commit bc50dfb

Browse files
Kevin Clarkmportuga
Kevin Clark
authored andcommitted
fix(Export): Eliminate selection column. Add export scale factor for excel and fonts
1 parent 7c2c002 commit bc50dfb

File tree

3 files changed

+68
-11
lines changed

3 files changed

+68
-11
lines changed

Diff for: misc/tutorial/410_excel_exporting_data_and_header.ngdoc

+1-6
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ Additionally, information about the Excel Builder may be found at https://github
3939

4040
If the example below we show how to make a custom header based on a callback method and
4141

42-
For better performance with the following example, you can choose to load the ui-grid.core.js and specific feature files instead:
43-
<pre>
44-
<script src="/release/ui-grid.core.min.js"></script>
45-
<script src="/release/ui-grid.exporter.min.js"></script>
46-
<script src="/release/ui-grid.selection.min.js"></script>
47-
</pre>
4842

4943
@example
5044
In this example we use the native grid menu buttons, and we show the pdf, csv and excel export options.
@@ -180,6 +174,7 @@ In this example we use the native grid menu buttons, and we show the pdf, csv an
180174
return null;
181175
}
182176
},
177+
exporterColumnScaleFactor: 4.5,
183178
exporterFieldApplyFilters: true,
184179
onRegisterApi: function(gridApi){
185180
$scope.gridApi = gridApi;

Diff for: src/features/exporter/js/exporter.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@
6262
module.constant('uiGridExporterConstants', {
6363
featureName: 'exporter',
6464
rowHeaderColName: 'treeBaseRowHeaderCol',
65+
selectionRowHeaderColName: 'selectionRowHeaderCol',
6566
ALL: 'all',
6667
VISIBLE: 'visible',
6768
SELECTED: 'selected',
6869
CSV_CONTENT: 'CSV_CONTENT',
6970
BUTTON_LABEL: 'BUTTON_LABEL',
70-
FILE_NAME: 'FILE_NAME',
71-
PIXEL_PER_UNIT: 75
71+
FILE_NAME: 'FILE_NAME'
7272
});
7373

7474
/**
@@ -560,6 +560,18 @@
560560
*/
561561
gridOptions.exporterFieldFormatCallback = gridOptions.exporterFieldFormatCallback ? gridOptions.exporterFieldFormatCallback : function( grid, row, col, value ) { return null; };
562562

563+
/**
564+
* @ngdoc object
565+
* @name exporterColumnScaleFactor
566+
* @propertyOf ui.grid.exporter.api:GridOptions
567+
* @description A scaling factor to divide the drawnwidth of a column to convert to target excel column
568+
* format size
569+
* @example
570+
* In this example we add a number to divide the drawnwidth of a column to get the excel width.
571+
* <br/>Defaults to 3.5
572+
*/
573+
gridOptions.exporterColumnScaleFactor = gridOptions.exporterColumnScaleFactor ? gridOptions.exporterColumnScaleFactor : 3.5;
574+
563575
/**
564576
* @ngdoc object
565577
* @name exporterFieldApplyFilters
@@ -1537,8 +1549,10 @@
15371549
var colWidths = [];
15381550
var startDataIndex = grid.treeBase ? grid.treeBase.numberLevels : (grid.enableRowSelection ? 1 : 0);
15391551
for (var i = startDataIndex; i < grid.columns.length; i++) {
1540-
if (grid.columns[i].field !== uiGridExporterConstants.rowHeaderColName) {
1541-
colWidths.push({width: (grid.columns[i].drawnWidth / uiGridExporterConstants.PIXEL_PER_UNIT) * 10});
1552+
if (grid.columns[i].field !== uiGridExporterConstants.rowHeaderColName &&
1553+
grid.columns[i].field !== uiGridExporterConstants.selectionRowHeaderColName) {
1554+
1555+
colWidths.push({width: (grid.columns[i].drawnWidth / grid.options.exporterColumnScaleFactor)});
15421556
}
15431557
}
15441558
sheet.setColumns(colWidths);
@@ -1555,7 +1569,8 @@
15551569
sheet.setData(sheet.data.concat(excelContent));
15561570

15571571
ExcelBuilder.Builder.createFile(workbook, {type:"blob"}).then(function(result) {
1558-
self.downloadFile (grid.options.exporterExcelFilename, result, grid.options.exporterCsvColumnSeparator, grid.options.exporterOlderExcelCompatibility);
1572+
self.downloadFile (grid.options.exporterExcelFilename, result, grid.options.exporterCsvColumnSeparator,
1573+
grid.options.exporterOlderExcelCompatibility);
15591574
});
15601575

15611576
});

Diff for: src/features/exporter/test/exporter.spec.js

+47
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,50 @@ describe('ui.grid.exporter', function() {
115115
});
116116
});
117117

118+
describe('defaultGridOptions', function() {
119+
var options;
120+
121+
beforeEach(function() {
122+
options = {};
123+
});
124+
125+
it('set all options to default', function () {
126+
uiGridExporterService.defaultGridOptions(options);
127+
expect(options).toEqual({
128+
exporterSuppressMenu: false,
129+
exporterMenuLabel: 'Export',
130+
exporterCsvColumnSeparator: ',',
131+
exporterCsvFilename: 'download.csv',
132+
exporterPdfFilename: 'download.pdf',
133+
exporterOlderExcelCompatibility: false,
134+
exporterIsExcelCompatible: false,
135+
exporterPdfDefaultStyle: {fontSize: 11},
136+
exporterPdfTableStyle: {margin: [0, 5, 0, 15]},
137+
exporterPdfTableHeaderStyle: {bold: true, fontSize: 12, color: 'black'},
138+
exporterPdfHeader: null,
139+
exporterPdfFooter: null,
140+
exporterPdfOrientation: 'landscape',
141+
exporterPdfPageSize: 'A4',
142+
exporterPdfMaxGridWidth: 720,
143+
exporterPdfCustomFormatter: jasmine.any(Function),
144+
exporterHeaderFilterUseName: false,
145+
exporterMenuAllData: true,
146+
exporterMenuVisibleData: true,
147+
exporterMenuSelectedData: true,
148+
exporterMenuCsv: true,
149+
exporterMenuPdf: true,
150+
exporterMenuExcel: true,
151+
exporterFieldCallback: jasmine.any(Function),
152+
exporterFieldFormatCallback: jasmine.any(Function),
153+
exporterFieldApplyFilters: false,
154+
exporterAllDataFn: null,
155+
exporterSuppressColumns: [],
156+
exporterColumnScaleFactor: 3.5,
157+
exporterMenuItemOrder: 200
158+
});
159+
});
160+
});
161+
118162
describe('defaultGridOptions', function() {
119163
var options;
120164

@@ -153,6 +197,7 @@ describe('ui.grid.exporter', function() {
153197
exporterFieldApplyFilters: false,
154198
exporterAllDataFn: null,
155199
exporterSuppressColumns: [],
200+
exporterColumnScaleFactor: 3.5,
156201
exporterMenuItemOrder: 200
157202
});
158203
});
@@ -194,6 +239,7 @@ describe('ui.grid.exporter', function() {
194239
exporterExcelSheetName: 'Sheet1',
195240
exporterExcelHeader: 'My Header',
196241
exporterExcelFooter: 'My Footer',
242+
exporterColumnScaleFactor: 3.5,
197243
exporterMenuItemOrder: 75
198244
};
199245
uiGridExporterService.defaultGridOptions(options);
@@ -231,6 +277,7 @@ describe('ui.grid.exporter', function() {
231277
exporterExcelSheetName: 'Sheet1',
232278
exporterExcelHeader: 'My Header',
233279
exporterExcelFooter: 'My Footer',
280+
exporterColumnScaleFactor: 3.5,
234281
exporterMenuItemOrder: 75,
235282
exporterAllDataFn: callback
236283
});

0 commit comments

Comments
 (0)