Skip to content

Commit f41f19b

Browse files
committed
Add option when exporting to get the cell display value rather than the source value
1 parent 54d6b58 commit f41f19b

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/features/exporter/js/exporter.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,8 +751,9 @@
751751
* @param {string} colTypes which columns to export, valid values are
752752
* uiGridExporterConstants.ALL, uiGridExporterConstants.VISIBLE,
753753
* uiGridExporterConstants.SELECTED
754+
* @param {boolean} applyCellFilters whether or not to get the display value or the raw value of the data
754755
*/
755-
getData: function (grid, rowTypes, colTypes) {
756+
getData: function (grid, rowTypes, colTypes, applyCellFilters) {
756757
var data = [];
757758
var rows;
758759
var columns;
@@ -793,7 +794,8 @@
793794
if ( (gridCol.visible || colTypes === uiGridExporterConstants.ALL ) &&
794795
gridCol.colDef.exporterSuppressExport !== true &&
795796
grid.options.exporterSuppressColumns.indexOf( gridCol.name ) === -1 ){
796-
var extractedField = { value: grid.options.exporterFieldCallback( grid, row, gridCol, grid.getCellValue( row, gridCol ) ) };
797+
var cellValue = applyCellFilters ? grid.getCellDisplayValue( row, gridCol ) : grid.getCellValue( row, gridCol );
798+
var extractedField = { value: grid.options.exporterFieldCallback( grid, row, gridCol, cellValue ) };
797799
if ( gridCol.colDef.exporterPdfAlign ) {
798800
extractedField.alignment = gridCol.colDef.exporterPdfAlign;
799801
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('ui.grid.exporter uiGridExporterService', function () {
2727
grid = gridClassFactory.createGrid({});
2828
grid.options.columnDefs = [
2929
{field: 'col1', name: 'col1', displayName: 'Col1', width: 50, pinnedLeft: true},
30-
{field: 'col2', name: 'col2', displayName: 'Col2', width: '*', type: 'number'},
30+
{field: 'col2', name: 'col2', displayName: 'Col2', width: '*', type: 'number', cellFilter: 'uppercase'},
3131
{field: 'col3', name: 'col3', displayName: 'Col3', width: 100},
3232
{field: 'col4', name: 'col4', displayName: 'Col4', width: 200}
3333
];
@@ -265,6 +265,14 @@ describe('ui.grid.exporter uiGridExporterService', function () {
265265
]);
266266
});
267267

268+
it('gets the rows display values', function() {
269+
expect(uiGridExporterService.getData(grid, uiGridExporterConstants.ALL, uiGridExporterConstants.ALL, true)).toEqual([
270+
[ {value: 'a_0'}, {value: 'B_0'}, {value: 'c_0'}, {value: 'd_0'} ],
271+
[ {value: 'a_1'}, {value: 'B_1'}, {value: 'c_1'}, {value: 'd_1'} ],
272+
[ {value: 'a_2'}, {value: 'B_2'}, {value: 'c_2'}, {value: 'd_2'} ]
273+
]);
274+
});
275+
268276
it('maps data using objectCallback', function() {
269277
grid.options.exporterFieldCallback = function( grid, row, col, value ){
270278
if ( col.name === 'col2' ){

0 commit comments

Comments
 (0)