Skip to content

Commit 0b37bc4

Browse files
committed
Included pinned columns in export of visibile data. Fixed issue #3888.
1 parent 7643a9e commit 0b37bc4

File tree

2 files changed

+101
-90
lines changed

2 files changed

+101
-90
lines changed

src/features/exporter/js/exporter.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,11 @@
674674
if ( colTypes === uiGridExporterConstants.ALL ){
675675
columns = grid.columns;
676676
} else {
677-
columns = grid.renderContainers.body.visibleColumnCache.filter( function( column ){ return column.visible; } );
677+
var leftColumns = grid.renderContainers.left ? grid.renderContainers.left.visibleColumnCache.filter( function( column ){ return column.visible; } ) : [];
678+
var bodyColumns = grid.renderContainers.body ? grid.renderContainers.body.visibleColumnCache.filter( function( column ){ return column.visible; } ) : [];
679+
var rightColumns = grid.renderContainers.right ? grid.renderContainers.right.visibleColumnCache.filter( function( column ){ return column.visible; } ) : [];
680+
681+
columns = leftColumns.concat(bodyColumns,rightColumns);
678682
}
679683

680684
columns.forEach( function( gridCol, index ) {
@@ -756,7 +760,11 @@
756760
if ( colTypes === uiGridExporterConstants.ALL ){
757761
columns = grid.columns;
758762
} else {
759-
columns = grid.renderContainers.body.visibleColumnCache.filter( function( column ){ return column.visible; } );
763+
var leftColumns = grid.renderContainers.left ? grid.renderContainers.left.visibleColumnCache.filter( function( column ){ return column.visible; } ) : [];
764+
var bodyColumns = grid.renderContainers.body ? grid.renderContainers.body.visibleColumnCache.filter( function( column ){ return column.visible; } ) : [];
765+
var rightColumns = grid.renderContainers.right ? grid.renderContainers.right.visibleColumnCache.filter( function( column ){ return column.visible; } ) : [];
766+
767+
columns = leftColumns.concat(bodyColumns,rightColumns);
760768
}
761769

762770
rows.forEach( function( row, index ) {

src/features/exporter/test/exporter.spec.js

+91-88
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ describe('ui.grid.exporter uiGridExporterService', function () {
99
var $scope;
1010
var $document;
1111

12-
beforeEach(module('ui.grid.exporter', 'ui.grid.selection'));
12+
beforeEach(module('ui.grid.exporter', 'ui.grid.selection', 'ui.grid.pinning'));
1313

1414

15-
beforeEach(inject(function (_uiGridExporterService_, _uiGridSelectionService_, _gridClassFactory_, _uiGridExporterConstants_,
15+
beforeEach(inject(function (_uiGridExporterService_, _uiGridSelectionService_, _uiGridPinningService_, _gridClassFactory_, _uiGridExporterConstants_,
16+
_uiGridPinningConstants_,
1617
_$compile_, _$rootScope_, _$document_, _uiGridSelectionConstants_) {
1718
uiGridExporterService = _uiGridExporterService_;
1819
uiGridSelectionService = _uiGridSelectionService_;
@@ -25,14 +26,15 @@ describe('ui.grid.exporter uiGridExporterService', function () {
2526

2627
grid = gridClassFactory.createGrid({});
2728
grid.options.columnDefs = [
28-
{field: 'col1', name: 'col1', displayName: 'Col1', width: 50},
29+
{field: 'col1', name: 'col1', displayName: 'Col1', width: 50, pinnedLeft: true},
2930
{field: 'col2', name: 'col2', displayName: 'Col2', width: '*', type: 'number'},
3031
{field: 'col3', name: 'col3', displayName: 'Col3', width: 100},
3132
{field: 'col4', name: 'col4', displayName: 'Col4', width: 200}
3233
];
3334

3435
_uiGridExporterService_.initializeGrid(grid);
3536
_uiGridSelectionService_.initializeGrid(grid);
37+
_uiGridPinningService_.initializeGrid(grid);
3638
var data = [];
3739
for (var i = 0; i < 3; i++) {
3840
data.push({col1:'a_'+i, col2:'b_'+i, col3:'c_'+i, col4:'d_'+i});
@@ -48,21 +50,22 @@ describe('ui.grid.exporter uiGridExporterService', function () {
4850

4951
grid.api.selection.clearSelectedRows();
5052
grid.api.selection.selectRow(grid.rows[0].entity);
51-
53+
5254
grid.gridWidth = 500;
53-
grid.columns[0].drawnWidth = 50;
54-
grid.columns[1].drawnWidth = '*';
55-
grid.columns[2].drawnWidth = 100;
56-
grid.columns[3].drawnWidth = 200;
55+
grid.columns[0].drawnWidth = 50;
56+
grid.columns[1].drawnWidth = '*';
57+
grid.columns[2].drawnWidth = 100;
58+
grid.columns[3].drawnWidth = 200;
59+
5760
}));
58-
61+
5962

6063
describe('defaultGridOptions', function() {
6164
var options;
6265
beforeEach(function() {
6366
options = {};
6467
});
65-
68+
6669
it('set all options to default', function() {
6770
uiGridExporterService.defaultGridOptions(options);
6871
expect( options ).toEqual({
@@ -87,7 +90,7 @@ describe('ui.grid.exporter uiGridExporterService', function () {
8790
exporterMenuPdf: true,
8891
exporterFieldCallback: jasmine.any(Function),
8992
exporterAllDataFn: null,
90-
exporterSuppressColumns: []
93+
exporterSuppressColumns: []
9194
});
9295
});
9396

@@ -143,7 +146,7 @@ describe('ui.grid.exporter uiGridExporterService', function () {
143146
exporterAllDataPromise: callback,
144147
exporterSuppressColumns: [ 'buttons' ]
145148
});
146-
});
149+
});
147150
});
148151

149152

@@ -254,7 +257,7 @@ describe('ui.grid.exporter uiGridExporterService', function () {
254257
expect(uiGridExporterService.getData(grid, uiGridExporterConstants.SELECTED, uiGridExporterConstants.VISIBLE)).toEqual([
255258
[ {value: 'a_0'}, {value: 'b_0'}, {value: 'd_0'} ]
256259
]);
257-
});
260+
});
258261

259262
it('maps data using objectCallback', function() {
260263
grid.options.exporterFieldCallback = function( grid, row, col, value ){
@@ -279,7 +282,7 @@ describe('ui.grid.exporter uiGridExporterService', function () {
279282
var columnHeaders = [];
280283
var data = [];
281284
var separator = ',';
282-
285+
283286
expect(uiGridExporterService.formatAsCsv(columnHeaders, data, separator)).toEqual(
284287
"\n"
285288
);
@@ -302,12 +305,12 @@ describe('ui.grid.exporter uiGridExporterService', function () {
302305
];
303306

304307
var separator = ',';
305-
308+
306309
expect(uiGridExporterService.formatAsCsv(columnHeaders, data, separator)).toEqual(
307310
'"Col1","Col2","Col3","12345234"\n"a string","a string","A string","a string"\n"","45","A string",FALSE\n"' + date.toISOString() + '",45,"A string",TRUE'
308311
);
309312
});
310-
313+
311314
it('formats a mix of data as a csv with custom separator', function() {
312315
var columnHeaders = [
313316
{name: 'col1', displayName: 'Col1', width: 50, align: 'left'},
@@ -323,9 +326,9 @@ describe('ui.grid.exporter uiGridExporterService', function () {
323326
[ {value: ''}, {value: '45'}, {value: 'A string'}, {value: false} ],
324327
[ {value: date}, {value: 45}, {value: 'A string'}, {value: true} ]
325328
];
326-
329+
327330
var separator = ';';
328-
331+
329332
expect(uiGridExporterService.formatAsCsv(columnHeaders, data, separator)).toEqual(
330333
'"Col1";"Col2";"Col3";"12345234"\n"a string";"a string";"A string";"a string"\n"";"45";"A string";FALSE\n"' + date.toISOString() + '";45;"A string";TRUE'
331334
);
@@ -353,51 +356,51 @@ describe('ui.grid.exporter uiGridExporterService', function () {
353356
[ {value: ''}, {value: '45'}, {value: 'A string'}, {value: false} ],
354357
[ {value: date}, {value: 45}, {value: 'A string'}, {value: true} ]
355358
];
356-
359+
357360
var result = uiGridExporterService.prepareAsPdf(grid, columnHeaders, data);
358361
expect(result).toEqual({
359362
pageOrientation : 'landscape',
360-
pageSize: 'A4',
361-
content : [{
363+
pageSize: 'A4',
364+
content : [{
362365
style : 'tableStyle',
363-
table : {
364-
headerRows : 1,
365-
widths: [50 * 720/450, '*', 100 * 720/450, 200 * 720/450],
366+
table : {
367+
headerRows : 1,
368+
widths: [50 * 720/450, '*', 100 * 720/450, 200 * 720/450],
366369
body : [
367-
[
368-
{ text : 'Col1', style : 'tableHeader' },
369-
{ text : 'Col2', style : 'tableHeader' },
370-
{ text : 'Col3', style : 'tableHeader' },
370+
[
371+
{ text : 'Col1', style : 'tableHeader' },
372+
{ text : 'Col2', style : 'tableHeader' },
373+
{ text : 'Col3', style : 'tableHeader' },
371374
{ text : '12345234', style : 'tableHeader' }
372-
],
373-
[ 'a string', 'a string', 'A string', 'a string' ],
374-
[ '', '45', 'A string', 'FALSE' ],
375-
[ date.toISOString(), '45', 'A string', 'TRUE' ]
376-
]
377-
}
378-
}],
379-
styles : {
380-
tableStyle : {
381-
margin : [ 0, 5, 0, 15 ]
382-
},
383-
tableHeader : {
384-
bold : true, fontSize : 12, color : 'black'
385-
}
386-
},
387-
defaultStyle : {
388-
fontSize : 11
375+
],
376+
[ 'a string', 'a string', 'A string', 'a string' ],
377+
[ '', '45', 'A string', 'FALSE' ],
378+
[ date.toISOString(), '45', 'A string', 'TRUE' ]
379+
]
380+
}
381+
}],
382+
styles : {
383+
tableStyle : {
384+
margin : [ 0, 5, 0, 15 ]
385+
},
386+
tableHeader : {
387+
bold : true, fontSize : 12, color : 'black'
388+
}
389+
},
390+
defaultStyle : {
391+
fontSize : 11
389392
}
390-
});
393+
});
391394

392395
});
393-
396+
394397
it( 'prepares standard grid using overrides', function() {
395398
/*
396399
* Note that you can test the results from prepareAsPdf using
397400
* http://pdfmake.org/playground.html#, which verifies
398401
* that it creates a genuine pdf
399402
*/
400-
403+
401404
grid.options.exporterPdfDefaultStyle = {fontSize: 10};
402405
grid.options.exporterPdfTableStyle = {margin: [30, 30, 30, 30]};
403406
grid.options.exporterPdfTableHeaderStyle = {fontSize: 11, bold: true, italic: true};
@@ -410,7 +413,7 @@ describe('ui.grid.exporter uiGridExporterService', function () {
410413
grid.options.exporterPdfOrientation = 'portrait';
411414
grid.options.exporterPdfPageSize = 'LETTER';
412415
grid.options.exporterPdfMaxGridWidth = 500;
413-
416+
414417
var columnHeaders = [
415418
{name: 'col1', displayName: 'Col1', width: 100, exporterPdfAlign: 'right'},
416419
{name: 'col2', displayName: 'Col2', width: '*', exporterPdfAlign: 'left'},
@@ -425,50 +428,50 @@ describe('ui.grid.exporter uiGridExporterService', function () {
425428
[ {value: '', alignment: 'right'}, {value: '45', alignment: 'center'}, {value: 'A string', alignment: 'left'}, {value: false} ],
426429
[ {value: date, alignment: 'right'}, {value: 45, alignment: 'center'}, {value: 'A string', alignment: 'left'}, {value: true} ]
427430
];
428-
431+
429432
var result = uiGridExporterService.prepareAsPdf(grid, columnHeaders, data);
430433
expect(result).toEqual({
431434
pageOrientation : 'portrait',
432-
pageSize: 'LETTER',
435+
pageSize: 'LETTER',
433436
content : [
434-
{
435-
style : 'tableStyle',
436-
table : {
437-
headerRows : 1,
438-
widths : [ 100, '*', 100, 200 ],
439-
body : [
440-
[
441-
{ text : 'Col1', style : 'tableHeader' },
442-
{ text : 'Col2', style : 'tableHeader' },
443-
{ text : 'Col3', style : 'tableHeader' },
444-
{ text : '12345234', style : 'tableHeader' }
445-
],
446-
[ {text: 'a string', alignment: 'right'}, { text: 'a string', alignment: 'center'}, { text: 'A string', alignment: 'left'}, 'a string' ],
447-
[ {text: '', alignment: 'right'}, {text: '45', alignment: 'center'}, {text: 'A string', alignment: 'left'}, 'FALSE' ],
448-
[ {text: date.toISOString(), alignment: 'right'}, {text: '45', alignment: 'center'}, {text: 'A string', alignment: 'left'}, 'TRUE' ]
449-
]
450-
}
437+
{
438+
style : 'tableStyle',
439+
table : {
440+
headerRows : 1,
441+
widths : [ 100, '*', 100, 200 ],
442+
body : [
443+
[
444+
{ text : 'Col1', style : 'tableHeader' },
445+
{ text : 'Col2', style : 'tableHeader' },
446+
{ text : 'Col3', style : 'tableHeader' },
447+
{ text : '12345234', style : 'tableHeader' }
448+
],
449+
[ {text: 'a string', alignment: 'right'}, { text: 'a string', alignment: 'center'}, { text: 'A string', alignment: 'left'}, 'a string' ],
450+
[ {text: '', alignment: 'right'}, {text: '45', alignment: 'center'}, {text: 'A string', alignment: 'left'}, 'FALSE' ],
451+
[ {text: date.toISOString(), alignment: 'right'}, {text: '45', alignment: 'center'}, {text: 'A string', alignment: 'left'}, 'TRUE' ]
452+
]
453+
}
451454
}
452455
],
453456
header : "My Header",
454-
footer : "My Footer",
455-
styles : {
456-
tableStyle : {
457-
margin : [ 30, 30, 30, 30 ]
458-
},
459-
tableHeader : {
460-
fontSize : 11, bold : true, italic : true
457+
footer : "My Footer",
458+
styles : {
459+
tableStyle : {
460+
margin : [ 30, 30, 30, 30 ]
461+
},
462+
tableHeader : {
463+
fontSize : 11, bold : true, italic : true
461464
},
462465
headerStyle: { fontSize: 10 }
463-
},
464-
defaultStyle : {
465-
fontSize : 10
466+
},
467+
defaultStyle : {
468+
fontSize : 10
466469
}
467-
});
468-
469-
});
470+
});
471+
472+
});
470473
});
471-
474+
472475
describe( 'calculatePdfHeaderWidths', function() {
473476
it( 'calculates mix of widths', function() {
474477
var headers = [
@@ -479,19 +482,19 @@ describe('ui.grid.exporter uiGridExporterService', function () {
479482
{ width: 150 },
480483
{ width: 100 }
481484
];
482-
485+
483486
grid.options.exporterPdfMaxGridWidth = 410;
484-
487+
485488
// baseGridWidth = 600
486489
// extra 120 for 20%
487490
// extra 100 for '*'
488491
// total gridWidth 820
489-
490-
492+
493+
491494
expect(uiGridExporterService.calculatePdfHeaderWidths( grid, headers)).toEqual(
492495
[60, '*', 75, 100, 75, 50]
493496
);
494497
});
495498
});
496-
497-
});
499+
500+
});

0 commit comments

Comments
 (0)