@ag-grid-community/csv-export
Advanced tools
Comparing version 22.0.0 to 22.1.0
@@ -1,2 +0,2 @@ | ||
import { Column, CsvExportParams, ExportParams, GridOptionsWrapper, ICsvCreator } from "@ag-grid-community/core"; | ||
import { CsvExportParams, ExportParams, GridOptionsWrapper, ICsvCreator, CsvCustomContent } from "@ag-grid-community/core"; | ||
import { BaseGridSerializingSession, GridSerializer, GridSerializingParams, GridSerializingSession, RowAccumulator, RowSpanningAccumulator } from "./gridSerializer"; | ||
@@ -8,13 +8,12 @@ import { Downloader } from "./downloader"; | ||
} | ||
export declare class CsvSerializingSession extends BaseGridSerializingSession<string> { | ||
export declare class CsvSerializingSession extends BaseGridSerializingSession<CsvCustomContent> { | ||
private isFirstLine; | ||
private result; | ||
private lineOpened; | ||
private suppressQuotes; | ||
private columnSeparator; | ||
constructor(config: CsvSerializingParams); | ||
prepare(columnsToExport: Column[]): void; | ||
addCustomHeader(customHeader: string): void; | ||
addCustomFooter(customFooter: string): void; | ||
addCustomContent(content: CsvCustomContent): void; | ||
onNewHeaderGroupingRow(): RowSpanningAccumulator; | ||
private onNewHeaderGroupingRowColumn; | ||
private appendEmptyCells; | ||
onNewHeaderRow(): RowAccumulator; | ||
@@ -26,2 +25,3 @@ private onNewHeaderRowColumn; | ||
parse(): string; | ||
private beginNewLine; | ||
} | ||
@@ -47,3 +47,3 @@ export interface BaseCreatorBeans { | ||
} | ||
export declare class CsvCreator extends BaseCreator<string, CsvSerializingSession, CsvExportParams> implements ICsvCreator { | ||
export declare class CsvCreator extends BaseCreator<CsvCustomContent, CsvSerializingSession, CsvExportParams> implements ICsvCreator { | ||
private columnController; | ||
@@ -50,0 +50,0 @@ private valueService; |
@@ -28,11 +28,5 @@ "use strict"; | ||
function CsvSerializingSession(config) { | ||
var _this = _super.call(this, { | ||
columnController: config.columnController, | ||
valueService: config.valueService, | ||
gridOptionsWrapper: config.gridOptionsWrapper, | ||
processCellCallback: config.processCellCallback, | ||
processHeaderCallback: config.processHeaderCallback | ||
}) || this; | ||
var _this = _super.call(this, config) || this; | ||
_this.isFirstLine = true; | ||
_this.result = ''; | ||
_this.lineOpened = false; | ||
var suppressQuotes = config.suppressQuotes, columnSeparator = config.columnSeparator; | ||
@@ -43,20 +37,34 @@ _this.suppressQuotes = suppressQuotes; | ||
} | ||
CsvSerializingSession.prototype.prepare = function (columnsToExport) { | ||
}; | ||
CsvSerializingSession.prototype.addCustomHeader = function (customHeader) { | ||
if (!customHeader) { | ||
CsvSerializingSession.prototype.addCustomContent = function (content) { | ||
var _this = this; | ||
if (!content) { | ||
return; | ||
} | ||
this.result += customHeader + LINE_SEPARATOR; | ||
}; | ||
CsvSerializingSession.prototype.addCustomFooter = function (customFooter) { | ||
if (!customFooter) { | ||
return; | ||
if (typeof content === 'string') { | ||
// we used to require the customFooter to be prefixed with a newline but no longer do, | ||
// so only add the newline if the user has not supplied one | ||
if (!/^\s*\n/.test(content)) { | ||
this.beginNewLine(); | ||
} | ||
// replace whatever newlines are supplied with the style we're using | ||
content = content.replace(/\r?\n/g, LINE_SEPARATOR); | ||
this.result += content; | ||
} | ||
this.result += customFooter + LINE_SEPARATOR; | ||
else { | ||
content.forEach(function (row) { | ||
_this.beginNewLine(); | ||
row.forEach(function (cell, index) { | ||
if (index !== 0) { | ||
_this.result += _this.columnSeparator; | ||
} | ||
_this.result += _this.putInQuotes(cell.data.value || ''); | ||
if (cell.mergeAcross) { | ||
_this.appendEmptyCells(cell.mergeAcross); | ||
} | ||
}); | ||
}); | ||
} | ||
}; | ||
CsvSerializingSession.prototype.onNewHeaderGroupingRow = function () { | ||
if (this.lineOpened) { | ||
this.result += LINE_SEPARATOR; | ||
} | ||
this.beginNewLine(); | ||
return { | ||
@@ -70,12 +78,12 @@ onColumn: this.onNewHeaderGroupingRowColumn.bind(this) | ||
} | ||
this.result += this.putInQuotes(header, this.suppressQuotes); | ||
for (var i = 1; i <= span; i++) { | ||
this.result += this.columnSeparator + this.putInQuotes("", this.suppressQuotes); | ||
this.result += this.putInQuotes(header); | ||
this.appendEmptyCells(span); | ||
}; | ||
CsvSerializingSession.prototype.appendEmptyCells = function (count) { | ||
for (var i = 1; i <= count; i++) { | ||
this.result += this.columnSeparator + this.putInQuotes(""); | ||
} | ||
this.lineOpened = true; | ||
}; | ||
CsvSerializingSession.prototype.onNewHeaderRow = function () { | ||
if (this.lineOpened) { | ||
this.result += LINE_SEPARATOR; | ||
} | ||
this.beginNewLine(); | ||
return { | ||
@@ -89,9 +97,6 @@ onColumn: this.onNewHeaderRowColumn.bind(this) | ||
} | ||
this.result += this.putInQuotes(this.extractHeaderValue(column), this.suppressQuotes); | ||
this.lineOpened = true; | ||
this.result += this.putInQuotes(this.extractHeaderValue(column)); | ||
}; | ||
CsvSerializingSession.prototype.onNewBodyRow = function () { | ||
if (this.lineOpened) { | ||
this.result += LINE_SEPARATOR; | ||
} | ||
this.beginNewLine(); | ||
return { | ||
@@ -105,7 +110,6 @@ onColumn: this.onNewBodyRowColumn.bind(this) | ||
} | ||
this.result += this.putInQuotes(this.extractRowCellValue(column, index, core_1.Constants.EXPORT_TYPE_CSV, node), this.suppressQuotes); | ||
this.lineOpened = true; | ||
this.result += this.putInQuotes(this.extractRowCellValue(column, index, core_1.Constants.EXPORT_TYPE_CSV, node)); | ||
}; | ||
CsvSerializingSession.prototype.putInQuotes = function (value, suppressQuotes) { | ||
if (suppressQuotes) { | ||
CsvSerializingSession.prototype.putInQuotes = function (value) { | ||
if (this.suppressQuotes) { | ||
return value; | ||
@@ -132,4 +136,10 @@ } | ||
CsvSerializingSession.prototype.parse = function () { | ||
return this.result; | ||
return this.result + LINE_SEPARATOR; | ||
}; | ||
CsvSerializingSession.prototype.beginNewLine = function () { | ||
if (!this.isFirstLine) { | ||
this.result += LINE_SEPARATOR; | ||
} | ||
this.isFirstLine = false; | ||
}; | ||
return CsvSerializingSession; | ||
@@ -210,3 +220,3 @@ }(gridSerializer_1.BaseGridSerializingSession)); | ||
var _a = this, columnController = _a.columnController, valueService = _a.valueService, gridOptionsWrapper = _a.gridOptionsWrapper; | ||
var processCellCallback = params.processCellCallback, processHeaderCallback = params.processHeaderCallback, processGroupHeaderCallback = params.processGroupHeaderCallback, suppressQuotes = params.suppressQuotes, columnSeparator = params.columnSeparator; | ||
var processCellCallback = params.processCellCallback, processHeaderCallback = params.processHeaderCallback, processGroupHeaderCallback = params.processGroupHeaderCallback, processRowGroupCallback = params.processRowGroupCallback, suppressQuotes = params.suppressQuotes, columnSeparator = params.columnSeparator; | ||
return new CsvSerializingSession({ | ||
@@ -219,2 +229,3 @@ columnController: columnController, | ||
processGroupHeaderCallback: processGroupHeaderCallback || undefined, | ||
processRowGroupCallback: processRowGroupCallback || undefined, | ||
suppressQuotes: suppressQuotes || false, | ||
@@ -251,1 +262,2 @@ columnSeparator: columnSeparator || ',' | ||
exports.CsvCreator = CsvCreator; | ||
//# sourceMappingURL=csvCreator.js.map |
@@ -43,1 +43,2 @@ "use strict"; | ||
exports.Downloader = Downloader; | ||
//# sourceMappingURL=downloader.js.map |
@@ -1,2 +0,2 @@ | ||
import { Column, ColumnController, ColumnGroupChild, ExportParams, GridOptionsWrapper, ProcessCellForExportParams, ProcessGroupHeaderForExportParams, ProcessHeaderForExportParams, RowNode, ValueService } from "@ag-grid-community/core"; | ||
import { Column, ColumnController, ColumnGroupChild, ExportParams, GridOptionsWrapper, ProcessCellForExportParams, ProcessGroupHeaderForExportParams, ProcessRowGroupForExportParams, ProcessHeaderForExportParams, RowNode, ValueService } from "@ag-grid-community/core"; | ||
/** | ||
@@ -6,35 +6,9 @@ * This interface works in conjunction with the GridSerializer. When serializing a grid, an instance that implements this interface | ||
* of the serialization. | ||
* | ||
* The lifecycle of a serializer with a GridSerializingSession is as follows. | ||
* | ||
* --1 Call to prepare method. An opportunity to do any required work before the call to accumulate data for the rows are about to happen. | ||
* --2 Call to the row methods as the serializer loops through the different rows of the grid will call these methods so that the data | ||
* can be accumulated. The methods. if there is relevant data will be called in the following order: | ||
* a) addCustomHeader | ||
* b) onNewHeaderGroupingRow | ||
* c) onNewHeader | ||
* d) onNewBodyRow | ||
* e) addCustomFooter | ||
* IF ANY OF THIS METHODS RETURN A ROW ACCUMULATOR, YOU CAN EXPECT THE SERIALIZER TO CALL ON THAT ACCUMULATOR WITH THE DATA FOR THAT ROW | ||
* IMMEDIATELY AFTER IT HAS RECEIVED THE OBJECT AND BEFORE IT CALLS YOU TO OBTAIN A NEW ROW ACCUMULATOR | ||
* --3 Call to parse method. This method is the last one to be called and is expected to return whatever accumulated | ||
* parsed string is to be returned as a result of the serialization | ||
* | ||
* This interface is closely related to the RowAccumulator and RowSpanningAccumulator interfaces as every time a new row is about | ||
* to be created a new instances of RowAccumulator or RowSpanningAccumulator need to be provided. | ||
*/ | ||
export interface GridSerializingSession<T> { | ||
/** | ||
* INITIAL METHOD | ||
*/ | ||
prepare(columnsToExport: Column[]): void; | ||
/** | ||
* ROW METHODS | ||
*/ | ||
addCustomHeader(customHeader: T): void; | ||
onNewHeaderGroupingRow(): RowSpanningAccumulator; | ||
onNewHeaderRow(): RowAccumulator; | ||
onNewBodyRow(): RowAccumulator; | ||
addCustomFooter(customFooter: T): void; | ||
addCustomContent(customContent: T): void; | ||
/** | ||
@@ -58,3 +32,3 @@ * FINAL RESULT | ||
processGroupHeaderCallback?: (params: ProcessGroupHeaderForExportParams) => string; | ||
cellAndHeaderEscaper?: (rawValue: string) => string; | ||
processRowGroupCallback?: (params: ProcessRowGroupForExportParams) => string; | ||
} | ||
@@ -68,7 +42,7 @@ export declare abstract class BaseGridSerializingSession<T> implements GridSerializingSession<T> { | ||
processGroupHeaderCallback?: (params: ProcessGroupHeaderForExportParams) => string; | ||
cellAndHeaderEscaper?: (rawValue: string) => string; | ||
processRowGroupCallback?: (params: ProcessRowGroupForExportParams) => string; | ||
private firstGroupColumn?; | ||
constructor(config: GridSerializingParams); | ||
abstract prepare(columnsToExport: Column[]): void; | ||
abstract addCustomHeader(customHeader: T): void; | ||
abstract addCustomFooter(customFooter: T): void; | ||
prepare(columnsToExport: Column[]): void; | ||
abstract addCustomContent(customContent: T): void; | ||
abstract onNewHeaderGroupingRow(): RowSpanningAccumulator; | ||
@@ -75,0 +49,0 @@ abstract onNewHeaderRow(): RowAccumulator; |
@@ -12,3 +12,3 @@ "use strict"; | ||
function BaseGridSerializingSession(config) { | ||
var columnController = config.columnController, valueService = config.valueService, gridOptionsWrapper = config.gridOptionsWrapper, processCellCallback = config.processCellCallback, processHeaderCallback = config.processHeaderCallback, processGroupHeaderCallback = config.processGroupHeaderCallback, cellAndHeaderEscaper = config.cellAndHeaderEscaper; | ||
var columnController = config.columnController, valueService = config.valueService, gridOptionsWrapper = config.gridOptionsWrapper, processCellCallback = config.processCellCallback, processHeaderCallback = config.processHeaderCallback, processGroupHeaderCallback = config.processGroupHeaderCallback, processRowGroupCallback = config.processRowGroupCallback; | ||
this.columnController = columnController; | ||
@@ -20,15 +20,23 @@ this.valueService = valueService; | ||
this.processGroupHeaderCallback = processGroupHeaderCallback; | ||
this.cellAndHeaderEscaper = cellAndHeaderEscaper; | ||
this.processRowGroupCallback = processRowGroupCallback; | ||
} | ||
BaseGridSerializingSession.prototype.prepare = function (columnsToExport) { | ||
this.firstGroupColumn = core_1._.find(columnsToExport, function (col) { return !!col.getColDef().showRowGroup; }); | ||
}; | ||
BaseGridSerializingSession.prototype.extractHeaderValue = function (column) { | ||
var nameForCol = this.getHeaderName(this.processHeaderCallback, column); | ||
if (nameForCol === null || nameForCol === undefined) { | ||
nameForCol = ''; | ||
} | ||
return this.cellAndHeaderEscaper ? this.cellAndHeaderEscaper(nameForCol) : nameForCol; | ||
var value = this.getHeaderName(this.processHeaderCallback, column); | ||
return value != null ? value : ''; | ||
}; | ||
BaseGridSerializingSession.prototype.extractRowCellValue = function (column, index, type, node) { | ||
var isGroupCell = node && node.group && !!column.getColDef().showRowGroup; | ||
// we render the group summary text e.g. "-> Parent -> Child"... | ||
var renderGroupSummaryCell = | ||
// on group rows | ||
node && node.group | ||
&& ( | ||
// in the first group column if groups appear in regular grid cells | ||
column === this.firstGroupColumn | ||
// or the first cell in the row, if we're doing full width rows | ||
|| (index === 0 && this.gridOptionsWrapper.isGroupUseEntireRow(this.columnController.isPivotMode()))); | ||
var valueForCell; | ||
if (isGroupCell) { | ||
if (renderGroupSummaryCell) { | ||
valueForCell = this.createValueForGroupNode(node); | ||
@@ -39,7 +47,4 @@ } | ||
} | ||
valueForCell = this.processCell(node, column, valueForCell, this.processCellCallback, type); | ||
if (valueForCell === null || valueForCell === undefined) { | ||
valueForCell = ''; | ||
} | ||
return this.cellAndHeaderEscaper ? this.cellAndHeaderEscaper(valueForCell) : valueForCell; | ||
var value = this.processCell(node, column, valueForCell, this.processCellCallback, type); | ||
return value != null ? value : ''; | ||
}; | ||
@@ -60,2 +65,10 @@ BaseGridSerializingSession.prototype.getHeaderName = function (callback, column) { | ||
BaseGridSerializingSession.prototype.createValueForGroupNode = function (node) { | ||
if (this.processRowGroupCallback) { | ||
return this.processRowGroupCallback({ | ||
node: node, | ||
api: this.gridOptionsWrapper.getApi(), | ||
columnApi: this.gridOptionsWrapper.getColumnApi(), | ||
context: this.gridOptionsWrapper.getContext(), | ||
}); | ||
} | ||
var keys = [node.key]; | ||
@@ -91,18 +104,6 @@ while (node.parent) { | ||
GridSerializer.prototype.serialize = function (gridSerializingSession, params) { | ||
var dontSkipRows = function () { return false; }; | ||
var skipGroups = params && params.skipGroups; | ||
var skipHeader = params && params.skipHeader; | ||
var columnGroups = params && params.columnGroups; | ||
var skipFooters = params && params.skipFooters; | ||
var skipPinnedTop = params && params.skipPinnedTop; | ||
var skipPinnedBottom = params && params.skipPinnedBottom; | ||
var includeCustomHeader = params && params.customHeader; | ||
var includeCustomFooter = params && params.customFooter; | ||
var allColumns = params && params.allColumns; | ||
var onlySelected = params && params.onlySelected; | ||
var columnKeys = params && params.columnKeys; | ||
var onlySelectedAllPages = params && params.onlySelectedAllPages; | ||
var processGroupHeaderCallback = params ? params.processGroupHeaderCallback : undefined; | ||
var rowSkipper = (params && params.shouldRowBeSkipped) || dontSkipRows; | ||
if (params === void 0) { params = {}; } | ||
var rowSkipper = params.shouldRowBeSkipped || (function () { return false; }); | ||
var api = this.gridOptionsWrapper.getApi(); | ||
var columnApi = this.gridOptionsWrapper.getColumnApi(); | ||
var skipSingleChildrenGroup = this.gridOptionsWrapper.isGroupRemoveSingleChildren(); | ||
@@ -114,8 +115,8 @@ var skipLowestSingleChildrenGroup = this.gridOptionsWrapper.isGroupRemoveLowestSingleChildren(); | ||
var rowModelNormal = this.rowModel.getType() === core_1.Constants.ROW_MODEL_TYPE_CLIENT_SIDE; | ||
var onlySelectedNonStandardModel = !rowModelNormal && onlySelected; | ||
var onlySelectedNonStandardModel = !rowModelNormal && params.onlySelected; | ||
var columnsToExport = []; | ||
if (core_1._.existsAndNotEmpty(columnKeys)) { | ||
columnsToExport = this.columnController.getGridColumns(columnKeys); | ||
if (core_1._.existsAndNotEmpty(params.columnKeys)) { | ||
columnsToExport = this.columnController.getGridColumns(params.columnKeys); | ||
} | ||
else if (allColumns && !isPivotMode) { | ||
else if (params.allColumns && !isPivotMode) { | ||
// add auto group column for tree data | ||
@@ -129,13 +130,13 @@ columnsToExport = this.gridOptionsWrapper.isTreeData() ? | ||
} | ||
if (includeCustomHeader) { | ||
gridSerializingSession.addCustomHeader(includeCustomHeader); | ||
if (params.customHeader) { | ||
gridSerializingSession.addCustomContent(params.customHeader); | ||
} | ||
gridSerializingSession.prepare(columnsToExport); | ||
// first pass, put in the header names of the cols | ||
if (columnGroups) { | ||
if (params.columnGroups) { | ||
var groupInstanceIdCreator = new core_1.GroupInstanceIdCreator(); | ||
var displayedGroups = this.displayedGroupCreator.createDisplayedGroups(columnsToExport, this.columnController.getGridBalancedTree(), groupInstanceIdCreator, null); | ||
this.recursivelyAddHeaderGroups(displayedGroups, gridSerializingSession, processGroupHeaderCallback); | ||
this.recursivelyAddHeaderGroups(displayedGroups, gridSerializingSession, params.processGroupHeaderCallback); | ||
} | ||
if (!skipHeader) { | ||
if (!params.skipHeader) { | ||
var gridRowIterator_1 = gridSerializingSession.onNewHeaderRow(); | ||
@@ -162,3 +163,3 @@ columnsToExport.forEach(function (column, index) { | ||
// (eg viewport) then again rowmodel cannot be used, so need to use selected instead. | ||
if (onlySelectedAllPages || onlySelectedNonStandardModel) { | ||
if (params.onlySelectedAllPages || onlySelectedNonStandardModel) { | ||
var selectedNodes = this.selectionController.getSelectedNodes(); | ||
@@ -182,4 +183,4 @@ selectedNodes.forEach(function (node) { | ||
this.pinnedRowModel.forEachPinnedBottomRow(processRow); | ||
if (includeCustomFooter) { | ||
gridSerializingSession.addCustomFooter(includeCustomFooter); | ||
if (params.customFooter) { | ||
gridSerializingSession.addCustomContent(params.customFooter); | ||
} | ||
@@ -189,15 +190,15 @@ function processRow(node) { | ||
var shouldSkipCurrentGroup = node.allChildrenCount === 1 && (skipSingleChildrenGroup || shouldSkipLowestGroup); | ||
if (node.group && (skipGroups || shouldSkipCurrentGroup)) { | ||
if (node.group && (params.skipGroups || shouldSkipCurrentGroup)) { | ||
return; | ||
} | ||
if (skipFooters && node.footer) { | ||
if (params.skipFooters && node.footer) { | ||
return; | ||
} | ||
if (onlySelected && !node.isSelected()) { | ||
if (params.onlySelected && !node.isSelected()) { | ||
return; | ||
} | ||
if (skipPinnedTop && node.rowPinned === 'top') { | ||
if (params.skipPinnedTop && node.rowPinned === 'top') { | ||
return; | ||
} | ||
if (skipPinnedBottom && node.rowPinned === 'bottom') { | ||
if (params.skipPinnedBottom && node.rowPinned === 'bottom') { | ||
return; | ||
@@ -211,7 +212,3 @@ } | ||
} | ||
var shouldRowBeSkipped = rowSkipper({ | ||
node: node, | ||
api: api, | ||
context: context | ||
}); | ||
var shouldRowBeSkipped = rowSkipper({ node: node, api: api, context: context }); | ||
if (shouldRowBeSkipped) { | ||
@@ -224,2 +221,8 @@ return; | ||
}); | ||
if (params.getCustomContentBelowRow) { | ||
var content = params.getCustomContentBelowRow({ node: node, api: api, columnApi: columnApi, context: context }); | ||
if (content) { | ||
gridSerializingSession.addCustomContent(content); | ||
} | ||
} | ||
} | ||
@@ -298,1 +301,2 @@ return gridSerializingSession.parse(); | ||
})(RowType = exports.RowType || (exports.RowType = {})); | ||
//# sourceMappingURL=gridSerializer.js.map |
@@ -81,1 +81,2 @@ "use strict"; | ||
exports.XmlFactory = XmlFactory; | ||
//# sourceMappingURL=xmlFactory.js.map |
@@ -189,1 +189,2 @@ "use strict"; | ||
exports.ZipContainer = ZipContainer; | ||
//# sourceMappingURL=zipContainer.js.map |
@@ -13,1 +13,2 @@ "use strict"; | ||
}; | ||
//# sourceMappingURL=csvExportModule.js.map |
@@ -18,1 +18,2 @@ "use strict"; | ||
exports.XmlFactory = xmlFactory_1.XmlFactory; | ||
//# sourceMappingURL=main.js.map |
@@ -1,2 +0,2 @@ | ||
import { Column, CsvExportParams, ExportParams, GridOptionsWrapper, ICsvCreator } from "@ag-grid-community/core"; | ||
import { CsvExportParams, ExportParams, GridOptionsWrapper, ICsvCreator, CsvCustomContent } from "@ag-grid-community/core"; | ||
import { BaseGridSerializingSession, GridSerializer, GridSerializingParams, GridSerializingSession, RowAccumulator, RowSpanningAccumulator } from "./gridSerializer"; | ||
@@ -8,13 +8,12 @@ import { Downloader } from "./downloader"; | ||
} | ||
export declare class CsvSerializingSession extends BaseGridSerializingSession<string> { | ||
export declare class CsvSerializingSession extends BaseGridSerializingSession<CsvCustomContent> { | ||
private isFirstLine; | ||
private result; | ||
private lineOpened; | ||
private suppressQuotes; | ||
private columnSeparator; | ||
constructor(config: CsvSerializingParams); | ||
prepare(columnsToExport: Column[]): void; | ||
addCustomHeader(customHeader: string): void; | ||
addCustomFooter(customFooter: string): void; | ||
addCustomContent(content: CsvCustomContent): void; | ||
onNewHeaderGroupingRow(): RowSpanningAccumulator; | ||
private onNewHeaderGroupingRowColumn; | ||
private appendEmptyCells; | ||
onNewHeaderRow(): RowAccumulator; | ||
@@ -26,2 +25,3 @@ private onNewHeaderRowColumn; | ||
parse(): string; | ||
private beginNewLine; | ||
} | ||
@@ -47,3 +47,3 @@ export interface BaseCreatorBeans { | ||
} | ||
export declare class CsvCreator extends BaseCreator<string, CsvSerializingSession, CsvExportParams> implements ICsvCreator { | ||
export declare class CsvCreator extends BaseCreator<CsvCustomContent, CsvSerializingSession, CsvExportParams> implements ICsvCreator { | ||
private columnController; | ||
@@ -50,0 +50,0 @@ private valueService; |
@@ -26,11 +26,5 @@ var __extends = (this && this.__extends) || (function () { | ||
function CsvSerializingSession(config) { | ||
var _this = _super.call(this, { | ||
columnController: config.columnController, | ||
valueService: config.valueService, | ||
gridOptionsWrapper: config.gridOptionsWrapper, | ||
processCellCallback: config.processCellCallback, | ||
processHeaderCallback: config.processHeaderCallback | ||
}) || this; | ||
var _this = _super.call(this, config) || this; | ||
_this.isFirstLine = true; | ||
_this.result = ''; | ||
_this.lineOpened = false; | ||
var suppressQuotes = config.suppressQuotes, columnSeparator = config.columnSeparator; | ||
@@ -41,20 +35,34 @@ _this.suppressQuotes = suppressQuotes; | ||
} | ||
CsvSerializingSession.prototype.prepare = function (columnsToExport) { | ||
}; | ||
CsvSerializingSession.prototype.addCustomHeader = function (customHeader) { | ||
if (!customHeader) { | ||
CsvSerializingSession.prototype.addCustomContent = function (content) { | ||
var _this = this; | ||
if (!content) { | ||
return; | ||
} | ||
this.result += customHeader + LINE_SEPARATOR; | ||
}; | ||
CsvSerializingSession.prototype.addCustomFooter = function (customFooter) { | ||
if (!customFooter) { | ||
return; | ||
if (typeof content === 'string') { | ||
// we used to require the customFooter to be prefixed with a newline but no longer do, | ||
// so only add the newline if the user has not supplied one | ||
if (!/^\s*\n/.test(content)) { | ||
this.beginNewLine(); | ||
} | ||
// replace whatever newlines are supplied with the style we're using | ||
content = content.replace(/\r?\n/g, LINE_SEPARATOR); | ||
this.result += content; | ||
} | ||
this.result += customFooter + LINE_SEPARATOR; | ||
else { | ||
content.forEach(function (row) { | ||
_this.beginNewLine(); | ||
row.forEach(function (cell, index) { | ||
if (index !== 0) { | ||
_this.result += _this.columnSeparator; | ||
} | ||
_this.result += _this.putInQuotes(cell.data.value || ''); | ||
if (cell.mergeAcross) { | ||
_this.appendEmptyCells(cell.mergeAcross); | ||
} | ||
}); | ||
}); | ||
} | ||
}; | ||
CsvSerializingSession.prototype.onNewHeaderGroupingRow = function () { | ||
if (this.lineOpened) { | ||
this.result += LINE_SEPARATOR; | ||
} | ||
this.beginNewLine(); | ||
return { | ||
@@ -68,12 +76,12 @@ onColumn: this.onNewHeaderGroupingRowColumn.bind(this) | ||
} | ||
this.result += this.putInQuotes(header, this.suppressQuotes); | ||
for (var i = 1; i <= span; i++) { | ||
this.result += this.columnSeparator + this.putInQuotes("", this.suppressQuotes); | ||
this.result += this.putInQuotes(header); | ||
this.appendEmptyCells(span); | ||
}; | ||
CsvSerializingSession.prototype.appendEmptyCells = function (count) { | ||
for (var i = 1; i <= count; i++) { | ||
this.result += this.columnSeparator + this.putInQuotes(""); | ||
} | ||
this.lineOpened = true; | ||
}; | ||
CsvSerializingSession.prototype.onNewHeaderRow = function () { | ||
if (this.lineOpened) { | ||
this.result += LINE_SEPARATOR; | ||
} | ||
this.beginNewLine(); | ||
return { | ||
@@ -87,9 +95,6 @@ onColumn: this.onNewHeaderRowColumn.bind(this) | ||
} | ||
this.result += this.putInQuotes(this.extractHeaderValue(column), this.suppressQuotes); | ||
this.lineOpened = true; | ||
this.result += this.putInQuotes(this.extractHeaderValue(column)); | ||
}; | ||
CsvSerializingSession.prototype.onNewBodyRow = function () { | ||
if (this.lineOpened) { | ||
this.result += LINE_SEPARATOR; | ||
} | ||
this.beginNewLine(); | ||
return { | ||
@@ -103,7 +108,6 @@ onColumn: this.onNewBodyRowColumn.bind(this) | ||
} | ||
this.result += this.putInQuotes(this.extractRowCellValue(column, index, Constants.EXPORT_TYPE_CSV, node), this.suppressQuotes); | ||
this.lineOpened = true; | ||
this.result += this.putInQuotes(this.extractRowCellValue(column, index, Constants.EXPORT_TYPE_CSV, node)); | ||
}; | ||
CsvSerializingSession.prototype.putInQuotes = function (value, suppressQuotes) { | ||
if (suppressQuotes) { | ||
CsvSerializingSession.prototype.putInQuotes = function (value) { | ||
if (this.suppressQuotes) { | ||
return value; | ||
@@ -130,4 +134,10 @@ } | ||
CsvSerializingSession.prototype.parse = function () { | ||
return this.result; | ||
return this.result + LINE_SEPARATOR; | ||
}; | ||
CsvSerializingSession.prototype.beginNewLine = function () { | ||
if (!this.isFirstLine) { | ||
this.result += LINE_SEPARATOR; | ||
} | ||
this.isFirstLine = false; | ||
}; | ||
return CsvSerializingSession; | ||
@@ -208,3 +218,3 @@ }(BaseGridSerializingSession)); | ||
var _a = this, columnController = _a.columnController, valueService = _a.valueService, gridOptionsWrapper = _a.gridOptionsWrapper; | ||
var processCellCallback = params.processCellCallback, processHeaderCallback = params.processHeaderCallback, processGroupHeaderCallback = params.processGroupHeaderCallback, suppressQuotes = params.suppressQuotes, columnSeparator = params.columnSeparator; | ||
var processCellCallback = params.processCellCallback, processHeaderCallback = params.processHeaderCallback, processGroupHeaderCallback = params.processGroupHeaderCallback, processRowGroupCallback = params.processRowGroupCallback, suppressQuotes = params.suppressQuotes, columnSeparator = params.columnSeparator; | ||
return new CsvSerializingSession({ | ||
@@ -217,2 +227,3 @@ columnController: columnController, | ||
processGroupHeaderCallback: processGroupHeaderCallback || undefined, | ||
processRowGroupCallback: processRowGroupCallback || undefined, | ||
suppressQuotes: suppressQuotes || false, | ||
@@ -219,0 +230,0 @@ columnSeparator: columnSeparator || ',' |
@@ -1,2 +0,2 @@ | ||
import { Column, ColumnController, ColumnGroupChild, ExportParams, GridOptionsWrapper, ProcessCellForExportParams, ProcessGroupHeaderForExportParams, ProcessHeaderForExportParams, RowNode, ValueService } from "@ag-grid-community/core"; | ||
import { Column, ColumnController, ColumnGroupChild, ExportParams, GridOptionsWrapper, ProcessCellForExportParams, ProcessGroupHeaderForExportParams, ProcessRowGroupForExportParams, ProcessHeaderForExportParams, RowNode, ValueService } from "@ag-grid-community/core"; | ||
/** | ||
@@ -6,35 +6,9 @@ * This interface works in conjunction with the GridSerializer. When serializing a grid, an instance that implements this interface | ||
* of the serialization. | ||
* | ||
* The lifecycle of a serializer with a GridSerializingSession is as follows. | ||
* | ||
* --1 Call to prepare method. An opportunity to do any required work before the call to accumulate data for the rows are about to happen. | ||
* --2 Call to the row methods as the serializer loops through the different rows of the grid will call these methods so that the data | ||
* can be accumulated. The methods. if there is relevant data will be called in the following order: | ||
* a) addCustomHeader | ||
* b) onNewHeaderGroupingRow | ||
* c) onNewHeader | ||
* d) onNewBodyRow | ||
* e) addCustomFooter | ||
* IF ANY OF THIS METHODS RETURN A ROW ACCUMULATOR, YOU CAN EXPECT THE SERIALIZER TO CALL ON THAT ACCUMULATOR WITH THE DATA FOR THAT ROW | ||
* IMMEDIATELY AFTER IT HAS RECEIVED THE OBJECT AND BEFORE IT CALLS YOU TO OBTAIN A NEW ROW ACCUMULATOR | ||
* --3 Call to parse method. This method is the last one to be called and is expected to return whatever accumulated | ||
* parsed string is to be returned as a result of the serialization | ||
* | ||
* This interface is closely related to the RowAccumulator and RowSpanningAccumulator interfaces as every time a new row is about | ||
* to be created a new instances of RowAccumulator or RowSpanningAccumulator need to be provided. | ||
*/ | ||
export interface GridSerializingSession<T> { | ||
/** | ||
* INITIAL METHOD | ||
*/ | ||
prepare(columnsToExport: Column[]): void; | ||
/** | ||
* ROW METHODS | ||
*/ | ||
addCustomHeader(customHeader: T): void; | ||
onNewHeaderGroupingRow(): RowSpanningAccumulator; | ||
onNewHeaderRow(): RowAccumulator; | ||
onNewBodyRow(): RowAccumulator; | ||
addCustomFooter(customFooter: T): void; | ||
addCustomContent(customContent: T): void; | ||
/** | ||
@@ -58,3 +32,3 @@ * FINAL RESULT | ||
processGroupHeaderCallback?: (params: ProcessGroupHeaderForExportParams) => string; | ||
cellAndHeaderEscaper?: (rawValue: string) => string; | ||
processRowGroupCallback?: (params: ProcessRowGroupForExportParams) => string; | ||
} | ||
@@ -68,7 +42,7 @@ export declare abstract class BaseGridSerializingSession<T> implements GridSerializingSession<T> { | ||
processGroupHeaderCallback?: (params: ProcessGroupHeaderForExportParams) => string; | ||
cellAndHeaderEscaper?: (rawValue: string) => string; | ||
processRowGroupCallback?: (params: ProcessRowGroupForExportParams) => string; | ||
private firstGroupColumn?; | ||
constructor(config: GridSerializingParams); | ||
abstract prepare(columnsToExport: Column[]): void; | ||
abstract addCustomHeader(customHeader: T): void; | ||
abstract addCustomFooter(customFooter: T): void; | ||
prepare(columnsToExport: Column[]): void; | ||
abstract addCustomContent(customContent: T): void; | ||
abstract onNewHeaderGroupingRow(): RowSpanningAccumulator; | ||
@@ -75,0 +49,0 @@ abstract onNewHeaderRow(): RowAccumulator; |
@@ -10,3 +10,3 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
function BaseGridSerializingSession(config) { | ||
var columnController = config.columnController, valueService = config.valueService, gridOptionsWrapper = config.gridOptionsWrapper, processCellCallback = config.processCellCallback, processHeaderCallback = config.processHeaderCallback, processGroupHeaderCallback = config.processGroupHeaderCallback, cellAndHeaderEscaper = config.cellAndHeaderEscaper; | ||
var columnController = config.columnController, valueService = config.valueService, gridOptionsWrapper = config.gridOptionsWrapper, processCellCallback = config.processCellCallback, processHeaderCallback = config.processHeaderCallback, processGroupHeaderCallback = config.processGroupHeaderCallback, processRowGroupCallback = config.processRowGroupCallback; | ||
this.columnController = columnController; | ||
@@ -18,15 +18,23 @@ this.valueService = valueService; | ||
this.processGroupHeaderCallback = processGroupHeaderCallback; | ||
this.cellAndHeaderEscaper = cellAndHeaderEscaper; | ||
this.processRowGroupCallback = processRowGroupCallback; | ||
} | ||
BaseGridSerializingSession.prototype.prepare = function (columnsToExport) { | ||
this.firstGroupColumn = _.find(columnsToExport, function (col) { return !!col.getColDef().showRowGroup; }); | ||
}; | ||
BaseGridSerializingSession.prototype.extractHeaderValue = function (column) { | ||
var nameForCol = this.getHeaderName(this.processHeaderCallback, column); | ||
if (nameForCol === null || nameForCol === undefined) { | ||
nameForCol = ''; | ||
} | ||
return this.cellAndHeaderEscaper ? this.cellAndHeaderEscaper(nameForCol) : nameForCol; | ||
var value = this.getHeaderName(this.processHeaderCallback, column); | ||
return value != null ? value : ''; | ||
}; | ||
BaseGridSerializingSession.prototype.extractRowCellValue = function (column, index, type, node) { | ||
var isGroupCell = node && node.group && !!column.getColDef().showRowGroup; | ||
// we render the group summary text e.g. "-> Parent -> Child"... | ||
var renderGroupSummaryCell = | ||
// on group rows | ||
node && node.group | ||
&& ( | ||
// in the first group column if groups appear in regular grid cells | ||
column === this.firstGroupColumn | ||
// or the first cell in the row, if we're doing full width rows | ||
|| (index === 0 && this.gridOptionsWrapper.isGroupUseEntireRow(this.columnController.isPivotMode()))); | ||
var valueForCell; | ||
if (isGroupCell) { | ||
if (renderGroupSummaryCell) { | ||
valueForCell = this.createValueForGroupNode(node); | ||
@@ -37,7 +45,4 @@ } | ||
} | ||
valueForCell = this.processCell(node, column, valueForCell, this.processCellCallback, type); | ||
if (valueForCell === null || valueForCell === undefined) { | ||
valueForCell = ''; | ||
} | ||
return this.cellAndHeaderEscaper ? this.cellAndHeaderEscaper(valueForCell) : valueForCell; | ||
var value = this.processCell(node, column, valueForCell, this.processCellCallback, type); | ||
return value != null ? value : ''; | ||
}; | ||
@@ -58,2 +63,10 @@ BaseGridSerializingSession.prototype.getHeaderName = function (callback, column) { | ||
BaseGridSerializingSession.prototype.createValueForGroupNode = function (node) { | ||
if (this.processRowGroupCallback) { | ||
return this.processRowGroupCallback({ | ||
node: node, | ||
api: this.gridOptionsWrapper.getApi(), | ||
columnApi: this.gridOptionsWrapper.getColumnApi(), | ||
context: this.gridOptionsWrapper.getContext(), | ||
}); | ||
} | ||
var keys = [node.key]; | ||
@@ -89,18 +102,6 @@ while (node.parent) { | ||
GridSerializer.prototype.serialize = function (gridSerializingSession, params) { | ||
var dontSkipRows = function () { return false; }; | ||
var skipGroups = params && params.skipGroups; | ||
var skipHeader = params && params.skipHeader; | ||
var columnGroups = params && params.columnGroups; | ||
var skipFooters = params && params.skipFooters; | ||
var skipPinnedTop = params && params.skipPinnedTop; | ||
var skipPinnedBottom = params && params.skipPinnedBottom; | ||
var includeCustomHeader = params && params.customHeader; | ||
var includeCustomFooter = params && params.customFooter; | ||
var allColumns = params && params.allColumns; | ||
var onlySelected = params && params.onlySelected; | ||
var columnKeys = params && params.columnKeys; | ||
var onlySelectedAllPages = params && params.onlySelectedAllPages; | ||
var processGroupHeaderCallback = params ? params.processGroupHeaderCallback : undefined; | ||
var rowSkipper = (params && params.shouldRowBeSkipped) || dontSkipRows; | ||
if (params === void 0) { params = {}; } | ||
var rowSkipper = params.shouldRowBeSkipped || (function () { return false; }); | ||
var api = this.gridOptionsWrapper.getApi(); | ||
var columnApi = this.gridOptionsWrapper.getColumnApi(); | ||
var skipSingleChildrenGroup = this.gridOptionsWrapper.isGroupRemoveSingleChildren(); | ||
@@ -112,8 +113,8 @@ var skipLowestSingleChildrenGroup = this.gridOptionsWrapper.isGroupRemoveLowestSingleChildren(); | ||
var rowModelNormal = this.rowModel.getType() === Constants.ROW_MODEL_TYPE_CLIENT_SIDE; | ||
var onlySelectedNonStandardModel = !rowModelNormal && onlySelected; | ||
var onlySelectedNonStandardModel = !rowModelNormal && params.onlySelected; | ||
var columnsToExport = []; | ||
if (_.existsAndNotEmpty(columnKeys)) { | ||
columnsToExport = this.columnController.getGridColumns(columnKeys); | ||
if (_.existsAndNotEmpty(params.columnKeys)) { | ||
columnsToExport = this.columnController.getGridColumns(params.columnKeys); | ||
} | ||
else if (allColumns && !isPivotMode) { | ||
else if (params.allColumns && !isPivotMode) { | ||
// add auto group column for tree data | ||
@@ -127,13 +128,13 @@ columnsToExport = this.gridOptionsWrapper.isTreeData() ? | ||
} | ||
if (includeCustomHeader) { | ||
gridSerializingSession.addCustomHeader(includeCustomHeader); | ||
if (params.customHeader) { | ||
gridSerializingSession.addCustomContent(params.customHeader); | ||
} | ||
gridSerializingSession.prepare(columnsToExport); | ||
// first pass, put in the header names of the cols | ||
if (columnGroups) { | ||
if (params.columnGroups) { | ||
var groupInstanceIdCreator = new GroupInstanceIdCreator(); | ||
var displayedGroups = this.displayedGroupCreator.createDisplayedGroups(columnsToExport, this.columnController.getGridBalancedTree(), groupInstanceIdCreator, null); | ||
this.recursivelyAddHeaderGroups(displayedGroups, gridSerializingSession, processGroupHeaderCallback); | ||
this.recursivelyAddHeaderGroups(displayedGroups, gridSerializingSession, params.processGroupHeaderCallback); | ||
} | ||
if (!skipHeader) { | ||
if (!params.skipHeader) { | ||
var gridRowIterator_1 = gridSerializingSession.onNewHeaderRow(); | ||
@@ -160,3 +161,3 @@ columnsToExport.forEach(function (column, index) { | ||
// (eg viewport) then again rowmodel cannot be used, so need to use selected instead. | ||
if (onlySelectedAllPages || onlySelectedNonStandardModel) { | ||
if (params.onlySelectedAllPages || onlySelectedNonStandardModel) { | ||
var selectedNodes = this.selectionController.getSelectedNodes(); | ||
@@ -180,4 +181,4 @@ selectedNodes.forEach(function (node) { | ||
this.pinnedRowModel.forEachPinnedBottomRow(processRow); | ||
if (includeCustomFooter) { | ||
gridSerializingSession.addCustomFooter(includeCustomFooter); | ||
if (params.customFooter) { | ||
gridSerializingSession.addCustomContent(params.customFooter); | ||
} | ||
@@ -187,15 +188,15 @@ function processRow(node) { | ||
var shouldSkipCurrentGroup = node.allChildrenCount === 1 && (skipSingleChildrenGroup || shouldSkipLowestGroup); | ||
if (node.group && (skipGroups || shouldSkipCurrentGroup)) { | ||
if (node.group && (params.skipGroups || shouldSkipCurrentGroup)) { | ||
return; | ||
} | ||
if (skipFooters && node.footer) { | ||
if (params.skipFooters && node.footer) { | ||
return; | ||
} | ||
if (onlySelected && !node.isSelected()) { | ||
if (params.onlySelected && !node.isSelected()) { | ||
return; | ||
} | ||
if (skipPinnedTop && node.rowPinned === 'top') { | ||
if (params.skipPinnedTop && node.rowPinned === 'top') { | ||
return; | ||
} | ||
if (skipPinnedBottom && node.rowPinned === 'bottom') { | ||
if (params.skipPinnedBottom && node.rowPinned === 'bottom') { | ||
return; | ||
@@ -209,7 +210,3 @@ } | ||
} | ||
var shouldRowBeSkipped = rowSkipper({ | ||
node: node, | ||
api: api, | ||
context: context | ||
}); | ||
var shouldRowBeSkipped = rowSkipper({ node: node, api: api, context: context }); | ||
if (shouldRowBeSkipped) { | ||
@@ -222,2 +219,8 @@ return; | ||
}); | ||
if (params.getCustomContentBelowRow) { | ||
var content = params.getCustomContentBelowRow({ node: node, api: api, columnApi: columnApi, context: context }); | ||
if (content) { | ||
gridSerializingSession.addCustomContent(content); | ||
} | ||
} | ||
} | ||
@@ -224,0 +227,0 @@ return gridSerializingSession.parse(); |
{ | ||
"name": "@ag-grid-community/csv-export", | ||
"version": "22.0.0", | ||
"version": "22.1.0", | ||
"description": "Advanced Data Grid / Data Table supporting Javascript / React / AngularJS / Web Components", | ||
"main": "./dist/cjs/main.js", | ||
"module": "./dist/es6/main.js", | ||
"types": "./dist/es6/main.d.ts", | ||
"scripts": { | ||
"build-cjs": "tsc -p tsconfig.es5.json", | ||
"build-cjs": "tsc -p tsconfig.json", | ||
"build-es6": "tsc -p tsconfig.es6.json", | ||
"build-docs": "tsc -p tsconfig.docs.json", | ||
"package": "node ../../common-build/rollup/build.js", | ||
"package": "node ../../module-build/rollup/build.js", | ||
"build": "npm run build-cjs && npm run build-es6" | ||
@@ -44,3 +44,3 @@ }, | ||
"dependencies": { | ||
"@ag-grid-community/core": "~22.0.0" | ||
"@ag-grid-community/core": "~22.1.0" | ||
}, | ||
@@ -53,2 +53,2 @@ "devDependencies": { | ||
} | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
5237791
45
81164
1
+ Added@ag-grid-community/core@22.1.1(transitive)
- Removed@ag-grid-community/core@22.0.0(transitive)