Socket
Socket
Sign inDemoInstall

@ag-grid-community/csv-export

Package Overview
Dependencies
Maintainers
3
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ag-grid-community/csv-export - npm Package Compare versions

Comparing version 25.0.1 to 25.1.0

dist/cjs/csvExport/baseCreator.d.ts

9

CONTRIBUTING.md

@@ -11,8 +11,7 @@ - [Question or Problem?](#question)

Please, do not open issues for the general support questions as we want to keep GitHub issues for bug reports and feature requests. You've got much better chances of getting your question answered on [StackOverflow](https://stackoverflow.com/questions/tagged/ag-grid) where the questions should be tagged with tag `ag-grid`,
or on our [Forum](https://ag-grid.com/forum)
Please, do not open issues for general support questions as we want to keep GitHub issues for bug reports and feature requests. You've got much better chances of getting your question answered on [StackOverflow](https://stackoverflow.com/questions/tagged/ag-grid) where the questions should be tagged with tag `ag-grid`.
If you're using the Enterprise version of ag-Grid (ag-grid-enterprise), then the [Members Forum](https://ag-grid.com/forum/forumdisplay.php?fid=5) is the best place to ask - you'll get a much quicker response there. Please contact accounts@ag-grid.com for access.
If you're using the Enterprise version of AG Grid (ag-grid-enterprise), then you should use our [Support Portal](https://ag-grid.zendesk.com/) - you'll get a much quicker response there. Please contact accounts@ag-grid.com for access.
To save your and our time we will be systematically closing all the issues that are requests for general support (for ag-Grid Free) and redirecting people to StackOverflow.
To save your and our time we will be systematically closing all the issues that are requests for general support (for AG Grid Community) and redirecting people to StackOverflow.

@@ -35,3 +34,3 @@ ## <a name="issue"></a> Found a Bug?

- version of ag-Grid used
- version of AG Grid used
- 3rd-party libraries and their versions

@@ -38,0 +37,0 @@ - and most importantly - a use-case that fails

@@ -1,45 +0,4 @@

import { CsvExportParams, ExportParams, GridOptionsWrapper, ICsvCreator, CsvCustomContent } from "@ag-grid-community/core";
import { BaseGridSerializingSession, GridSerializer, GridSerializingParams, GridSerializingSession, RowAccumulator, RowSpanningAccumulator } from "./gridSerializer";
import { Downloader } from "./downloader";
export interface CsvSerializingParams extends GridSerializingParams {
suppressQuotes: boolean;
columnSeparator: string;
}
export declare class CsvSerializingSession extends BaseGridSerializingSession<CsvCustomContent> {
private isFirstLine;
private result;
private suppressQuotes;
private columnSeparator;
constructor(config: CsvSerializingParams);
addCustomContent(content: CsvCustomContent): void;
onNewHeaderGroupingRow(): RowSpanningAccumulator;
private onNewHeaderGroupingRowColumn;
private appendEmptyCells;
onNewHeaderRow(): RowAccumulator;
private onNewHeaderRowColumn;
onNewBodyRow(): RowAccumulator;
private onNewBodyRowColumn;
private putInQuotes;
parse(): string;
private beginNewLine;
}
export interface BaseCreatorBeans {
downloader: Downloader;
gridSerializer: GridSerializer;
gridOptionsWrapper: GridOptionsWrapper;
}
export declare abstract class BaseCreator<T, S extends GridSerializingSession<T>, P extends ExportParams<T>> {
private beans;
protected setBeans(beans: BaseCreatorBeans): void;
export(userParams?: P): string;
getData(params?: P): string;
private getMergedParamsAndData;
private mergeDefaultParams;
protected packageFile(data: string): Blob;
abstract createSerializingSession(params?: P): S;
abstract getMimeType(): string;
abstract getDefaultFileName(): string;
abstract getDefaultFileExtension(): string;
abstract isExportSuppressed(): boolean;
}
import { CsvCustomContent, CsvExportParams, GridOptionsWrapper, ICsvCreator } from "@ag-grid-community/core";
import { BaseCreator } from "./baseCreator";
import { CsvSerializingSession } from "./sessions/csvSerializingSession";
export declare class CsvCreator extends BaseCreator<CsvCustomContent, CsvSerializingSession, CsvExportParams> implements ICsvCreator {

@@ -46,0 +5,0 @@ private columnController;

@@ -23,164 +23,4 @@ "use strict";

var core_1 = require("@ag-grid-community/core");
var gridSerializer_1 = require("./gridSerializer");
var LINE_SEPARATOR = '\r\n';
var CsvSerializingSession = /** @class */ (function (_super) {
__extends(CsvSerializingSession, _super);
function CsvSerializingSession(config) {
var _this = _super.call(this, config) || this;
_this.isFirstLine = true;
_this.result = '';
var suppressQuotes = config.suppressQuotes, columnSeparator = config.columnSeparator;
_this.suppressQuotes = suppressQuotes;
_this.columnSeparator = columnSeparator;
return _this;
}
CsvSerializingSession.prototype.addCustomContent = function (content) {
var _this = this;
if (!content) {
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;
}
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 () {
this.beginNewLine();
return {
onColumn: this.onNewHeaderGroupingRowColumn.bind(this)
};
};
CsvSerializingSession.prototype.onNewHeaderGroupingRowColumn = function (header, index, span) {
if (index != 0) {
this.result += this.columnSeparator;
}
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("");
}
};
CsvSerializingSession.prototype.onNewHeaderRow = function () {
this.beginNewLine();
return {
onColumn: this.onNewHeaderRowColumn.bind(this)
};
};
CsvSerializingSession.prototype.onNewHeaderRowColumn = function (column, index, node) {
if (index != 0) {
this.result += this.columnSeparator;
}
this.result += this.putInQuotes(this.extractHeaderValue(column));
};
CsvSerializingSession.prototype.onNewBodyRow = function () {
this.beginNewLine();
return {
onColumn: this.onNewBodyRowColumn.bind(this)
};
};
CsvSerializingSession.prototype.onNewBodyRowColumn = function (column, index, node) {
if (index != 0) {
this.result += this.columnSeparator;
}
this.result += this.putInQuotes(this.extractRowCellValue(column, index, core_1.Constants.EXPORT_TYPE_CSV, node));
};
CsvSerializingSession.prototype.putInQuotes = function (value) {
if (this.suppressQuotes) {
return value;
}
if (value === null || value === undefined) {
return '""';
}
var stringValue;
if (typeof value === 'string') {
stringValue = value;
}
else if (typeof value.toString === 'function') {
stringValue = value.toString();
}
else {
console.warn('unknown value type during csv conversion');
stringValue = '';
}
// replace each " with "" (ie two sets of double quotes is how to do double quotes in csv)
var valueEscaped = stringValue.replace(/"/g, "\"\"");
return '"' + valueEscaped + '"';
};
CsvSerializingSession.prototype.parse = function () {
return this.result;
};
CsvSerializingSession.prototype.beginNewLine = function () {
if (!this.isFirstLine) {
this.result += LINE_SEPARATOR;
}
this.isFirstLine = false;
};
return CsvSerializingSession;
}(gridSerializer_1.BaseGridSerializingSession));
exports.CsvSerializingSession = CsvSerializingSession;
var BaseCreator = /** @class */ (function () {
function BaseCreator() {
}
BaseCreator.prototype.setBeans = function (beans) {
this.beans = beans;
};
BaseCreator.prototype.export = function (userParams) {
if (this.isExportSuppressed()) {
console.warn("ag-grid: Export cancelled. Export is not allowed as per your configuration.");
return '';
}
var _a = this.getMergedParamsAndData(userParams), mergedParams = _a.mergedParams, data = _a.data;
var fileNamePresent = mergedParams && mergedParams.fileName && mergedParams.fileName.length !== 0;
var fileName = fileNamePresent ? mergedParams.fileName : this.getDefaultFileName();
if (fileName.indexOf(".") === -1) {
fileName = fileName + "." + this.getDefaultFileExtension();
}
this.beans.downloader.download(fileName, this.packageFile(data));
return data;
};
BaseCreator.prototype.getData = function (params) {
return this.getMergedParamsAndData(params).data;
};
BaseCreator.prototype.getMergedParamsAndData = function (userParams) {
var mergedParams = this.mergeDefaultParams(userParams);
var data = this.beans.gridSerializer.serialize(this.createSerializingSession(mergedParams), mergedParams);
return { mergedParams: mergedParams, data: data };
};
BaseCreator.prototype.mergeDefaultParams = function (userParams) {
var baseParams = this.beans.gridOptionsWrapper.getDefaultExportParams();
var params = {};
core_1._.assign(params, baseParams);
core_1._.assign(params, userParams);
return params;
};
BaseCreator.prototype.packageFile = function (data) {
return new Blob(["\ufeff", data], {
type: window.navigator.msSaveOrOpenBlob ? this.getMimeType() : 'octet/stream'
});
};
return BaseCreator;
}());
exports.BaseCreator = BaseCreator;
var baseCreator_1 = require("./baseCreator");
var csvSerializingSession_1 = require("./sessions/csvSerializingSession");
var CsvCreator = /** @class */ (function (_super) {

@@ -216,3 +56,3 @@ __extends(CsvCreator, _super);

var _b = params, processCellCallback = _b.processCellCallback, processHeaderCallback = _b.processHeaderCallback, processGroupHeaderCallback = _b.processGroupHeaderCallback, processRowGroupCallback = _b.processRowGroupCallback, suppressQuotes = _b.suppressQuotes, columnSeparator = _b.columnSeparator;
return new CsvSerializingSession({
return new csvSerializingSession_1.CsvSerializingSession({
columnController: columnController,

@@ -254,4 +94,4 @@ valueService: valueService,

return CsvCreator;
}(BaseCreator));
}(baseCreator_1.BaseCreator));
exports.CsvCreator = CsvCreator;
//# sourceMappingURL=csvCreator.js.map

@@ -1,55 +0,3 @@

import { Column, ColumnController, ColumnGroupChild, ExportParams, GridOptionsWrapper, ProcessCellForExportParams, ProcessGroupHeaderForExportParams, ProcessRowGroupForExportParams, ProcessHeaderForExportParams, RowNode, ValueService, BeanStub } from "@ag-grid-community/core";
/**
* This interface works in conjunction with the GridSerializer. When serializing a grid, an instance that implements this interface
* must be passed in, the serializer will call back to the provided methods and finally call to parse to obtain the final result
* of the serialization.
*/
export interface GridSerializingSession<T> {
prepare(columnsToExport: Column[]): void;
onNewHeaderGroupingRow(): RowSpanningAccumulator;
onNewHeaderRow(): RowAccumulator;
onNewBodyRow(): RowAccumulator;
addCustomContent(customContent: T): void;
/**
* FINAL RESULT
*/
parse(): string;
}
export interface RowAccumulator {
onColumn(column: Column, index: number, node?: RowNode): void;
}
export interface RowSpanningAccumulator {
onColumn(header: string, index: number, span: number): void;
}
export interface GridSerializingParams {
columnController: ColumnController;
valueService: ValueService;
gridOptionsWrapper: GridOptionsWrapper;
processCellCallback?: (params: ProcessCellForExportParams) => string;
processHeaderCallback?: (params: ProcessHeaderForExportParams) => string;
processGroupHeaderCallback?: (params: ProcessGroupHeaderForExportParams) => string;
processRowGroupCallback?: (params: ProcessRowGroupForExportParams) => string;
}
export declare abstract class BaseGridSerializingSession<T> implements GridSerializingSession<T> {
columnController: ColumnController;
valueService: ValueService;
gridOptionsWrapper: GridOptionsWrapper;
processCellCallback?: (params: ProcessCellForExportParams) => string;
processHeaderCallback?: (params: ProcessHeaderForExportParams) => string;
processGroupHeaderCallback?: (params: ProcessGroupHeaderForExportParams) => string;
processRowGroupCallback?: (params: ProcessRowGroupForExportParams) => string;
private groupColumns;
constructor(config: GridSerializingParams);
abstract addCustomContent(customContent: T): void;
abstract onNewHeaderGroupingRow(): RowSpanningAccumulator;
abstract onNewHeaderRow(): RowAccumulator;
abstract onNewBodyRow(): RowAccumulator;
abstract parse(): string;
prepare(columnsToExport: Column[]): void;
extractHeaderValue(column: Column): string;
extractRowCellValue(column: Column, index: number, type: string, node: RowNode): any;
private getHeaderName;
private createValueForGroupNode;
private processCell;
}
import { BeanStub, ColumnGroupChild, ExportParams, ProcessGroupHeaderForExportParams } from "@ag-grid-community/core";
import { GridSerializingSession } from "./interfaces";
export declare class GridSerializer extends BeanStub {

@@ -61,3 +9,2 @@ private displayedGroupCreator;

private selectionController;
private columnFactory;
serialize<T>(gridSerializingSession: GridSerializingSession<T>, params?: ExportParams<T>): string;

@@ -64,0 +11,0 @@ recursivelyAddHeaderGroups<T>(displayedGroups: ColumnGroupChild[], gridSerializingSession: GridSerializingSession<T>, processGroupHeaderCallback: ProcessGroupHeaderCallback | undefined): void;

@@ -23,88 +23,2 @@ "use strict";

var core_1 = require("@ag-grid-community/core");
var BaseGridSerializingSession = /** @class */ (function () {
function BaseGridSerializingSession(config) {
this.groupColumns = [];
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;
this.valueService = valueService;
this.gridOptionsWrapper = gridOptionsWrapper;
this.processCellCallback = processCellCallback;
this.processHeaderCallback = processHeaderCallback;
this.processGroupHeaderCallback = processGroupHeaderCallback;
this.processRowGroupCallback = processRowGroupCallback;
}
BaseGridSerializingSession.prototype.prepare = function (columnsToExport) {
this.groupColumns = core_1._.filter(columnsToExport, function (col) { return !!col.getColDef().showRowGroup; });
};
BaseGridSerializingSession.prototype.extractHeaderValue = function (column) {
var value = this.getHeaderName(this.processHeaderCallback, column);
return value != null ? value : '';
};
BaseGridSerializingSession.prototype.extractRowCellValue = function (column, index, type, node) {
// we render the group summary text e.g. "-> Parent -> Child"...
var groupIndex = this.gridOptionsWrapper.isGroupMultiAutoColumn() ? node.rowGroupIndex : 0;
var renderGroupSummaryCell =
// on group rows
node && node.group
&& (
// in the group column if groups appear in regular grid cells
index === groupIndex && this.groupColumns.indexOf(column) !== -1
// 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 (renderGroupSummaryCell) {
valueForCell = this.createValueForGroupNode(node);
}
else {
valueForCell = this.valueService.getValue(column, node);
}
var value = this.processCell(node, column, valueForCell, this.processCellCallback, type);
return value != null ? value : '';
};
BaseGridSerializingSession.prototype.getHeaderName = function (callback, column) {
if (callback) {
return callback({
column: column,
api: this.gridOptionsWrapper.getApi(),
columnApi: this.gridOptionsWrapper.getColumnApi(),
context: this.gridOptionsWrapper.getContext()
});
}
return this.columnController.getDisplayNameForColumn(column, 'csv', true);
};
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];
if (!this.gridOptionsWrapper.isGroupMultiAutoColumn()) {
while (node.parent) {
node = node.parent;
keys.push(node.key);
}
}
return keys.reverse().join(' -> ');
};
BaseGridSerializingSession.prototype.processCell = function (rowNode, column, value, processCellCallback, type) {
if (processCellCallback) {
return processCellCallback({
column: column,
node: rowNode,
value: value,
api: this.gridOptionsWrapper.getApi(),
columnApi: this.gridOptionsWrapper.getColumnApi(),
context: this.gridOptionsWrapper.getContext(),
type: type
});
}
return value;
};
return BaseGridSerializingSession;
}());
exports.BaseGridSerializingSession = BaseGridSerializingSession;
var GridSerializer = /** @class */ (function (_super) {

@@ -118,7 +32,9 @@ __extends(GridSerializer, _super);

var rowSkipper = params.shouldRowBeSkipped || (function () { return false; });
var api = this.gridOptionsWrapper.getApi();
var columnApi = this.gridOptionsWrapper.getColumnApi();
var skipSingleChildrenGroup = this.gridOptionsWrapper.isGroupRemoveSingleChildren();
var skipLowestSingleChildrenGroup = this.gridOptionsWrapper.isGroupRemoveLowestSingleChildren();
var context = this.gridOptionsWrapper.getContext();
var gridOptionsWrapper = this.gridOptionsWrapper;
var api = gridOptionsWrapper.getApi();
var columnApi = gridOptionsWrapper.getColumnApi();
var skipSingleChildrenGroup = gridOptionsWrapper.isGroupRemoveSingleChildren();
var skipLowestSingleChildrenGroup = gridOptionsWrapper.isGroupRemoveLowestSingleChildren();
var hideOpenParents = gridOptionsWrapper.isGroupHideOpenParents();
var context = gridOptionsWrapper.getContext();
// when in pivot mode, we always render cols on screen, never 'all columns'

@@ -134,3 +50,3 @@ var isPivotMode = this.columnController.isPivotMode();

// add auto group column for tree data
columnsToExport = this.gridOptionsWrapper.isTreeData() ?
columnsToExport = gridOptionsWrapper.isTreeData() ?
this.columnController.getGridColumns([core_1.Constants.GROUP_AUTO_COLUMN_ID]) : [];

@@ -159,9 +75,12 @@ columnsToExport = columnsToExport.concat(this.columnController.getAllPrimaryColumns() || []);

this.pinnedRowModel.forEachPinnedTopRow(processRow);
var rowModel = this.rowModel;
var clientSideRowModel = this.rowModel;
if (isPivotMode) {
if (this.rowModel.forEachPivotNode) {
this.rowModel.forEachPivotNode(processRow);
// @ts-ignore - ignore tautology below as we are using it to check if it's clientSideRowModel
if (clientSideRowModel.forEachPivotNode) {
clientSideRowModel.forEachPivotNode(processRow);
}
else {
//Must be enterprise, so we can just loop through all the nodes
this.rowModel.forEachNode(processRow);
// n=must be enterprise, so we can just loop through all the nodes
rowModel.forEachNode(processRow);
}

@@ -174,3 +93,3 @@ }

// onlySelectedNonStandardModel: if user wants selected in non standard row model
// (eg viewport) then again rowmodel cannot be used, so need to use selected instead.
// (eg viewport) then again RowModel cannot be used, so need to use selected instead.
if (params.onlySelectedAllPages || onlySelectedNonStandardModel) {

@@ -187,6 +106,6 @@ var selectedNodes = this.selectionController.getSelectedNodes();

if (rowModelNormal) {
this.rowModel.forEachNodeAfterFilterAndSort(processRow);
clientSideRowModel.forEachNodeAfterFilterAndSort(processRow);
}
else {
this.rowModel.forEachNode(processRow);
rowModel.forEachNode(processRow);
}

@@ -202,3 +121,3 @@ }

var shouldSkipCurrentGroup = node.allChildrenCount === 1 && (skipSingleChildrenGroup || shouldSkipLowestGroup);
if (node.group && (params.skipGroups || shouldSkipCurrentGroup)) {
if (node.group && (params.skipGroups || shouldSkipCurrentGroup || hideOpenParents)) {
return;

@@ -293,5 +212,2 @@ }

], GridSerializer.prototype, "selectionController", void 0);
__decorate([
core_1.Autowired('columnFactory')
], GridSerializer.prototype, "columnFactory", void 0);
GridSerializer = __decorate([

@@ -298,0 +214,0 @@ core_1.Bean("gridSerializer")

@@ -1,6 +0,9 @@

export { CsvExportModule } from "./csvExportModule";
export { BaseCreator, CsvCreator } from "./csvExport/csvCreator";
export { Downloader } from "./csvExport/downloader";
export { GridSerializer, RowType, RowSpanningAccumulator, BaseGridSerializingSession, GridSerializingParams, RowAccumulator } from "./csvExport/gridSerializer";
export { ZipContainer } from "./csvExport/zipContainer";
export { XmlFactory } from "./csvExport/xmlFactory";
export { BaseCreator } from './csvExport/baseCreator';
export { BaseGridSerializingSession } from './csvExport/sessions/baseGridSerializingSession';
export { CsvCreator } from './csvExport/csvCreator';
export { CsvExportModule } from './csvExportModule';
export { Downloader } from './csvExport/downloader';
export { GridSerializer, RowType } from './csvExport/gridSerializer';
export { RowSpanningAccumulator, GridSerializingParams, RowAccumulator } from './csvExport/interfaces';
export { XmlFactory } from './csvExport/xmlFactory';
export { ZipContainer } from './csvExport/zipContainer';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var baseCreator_1 = require("./csvExport/baseCreator");
exports.BaseCreator = baseCreator_1.BaseCreator;
var baseGridSerializingSession_1 = require("./csvExport/sessions/baseGridSerializingSession");
exports.BaseGridSerializingSession = baseGridSerializingSession_1.BaseGridSerializingSession;
var csvCreator_1 = require("./csvExport/csvCreator");
exports.CsvCreator = csvCreator_1.CsvCreator;
var csvExportModule_1 = require("./csvExportModule");
exports.CsvExportModule = csvExportModule_1.CsvExportModule;
var csvCreator_1 = require("./csvExport/csvCreator");
exports.BaseCreator = csvCreator_1.BaseCreator;
exports.CsvCreator = csvCreator_1.CsvCreator;
var downloader_1 = require("./csvExport/downloader");

@@ -13,7 +16,6 @@ exports.Downloader = downloader_1.Downloader;

exports.RowType = gridSerializer_1.RowType;
exports.BaseGridSerializingSession = gridSerializer_1.BaseGridSerializingSession;
var xmlFactory_1 = require("./csvExport/xmlFactory");
exports.XmlFactory = xmlFactory_1.XmlFactory;
var zipContainer_1 = require("./csvExport/zipContainer");
exports.ZipContainer = zipContainer_1.ZipContainer;
var xmlFactory_1 = require("./csvExport/xmlFactory");
exports.XmlFactory = xmlFactory_1.XmlFactory;
//# sourceMappingURL=main.js.map

@@ -1,45 +0,4 @@

import { CsvExportParams, ExportParams, GridOptionsWrapper, ICsvCreator, CsvCustomContent } from "@ag-grid-community/core";
import { BaseGridSerializingSession, GridSerializer, GridSerializingParams, GridSerializingSession, RowAccumulator, RowSpanningAccumulator } from "./gridSerializer";
import { Downloader } from "./downloader";
export interface CsvSerializingParams extends GridSerializingParams {
suppressQuotes: boolean;
columnSeparator: string;
}
export declare class CsvSerializingSession extends BaseGridSerializingSession<CsvCustomContent> {
private isFirstLine;
private result;
private suppressQuotes;
private columnSeparator;
constructor(config: CsvSerializingParams);
addCustomContent(content: CsvCustomContent): void;
onNewHeaderGroupingRow(): RowSpanningAccumulator;
private onNewHeaderGroupingRowColumn;
private appendEmptyCells;
onNewHeaderRow(): RowAccumulator;
private onNewHeaderRowColumn;
onNewBodyRow(): RowAccumulator;
private onNewBodyRowColumn;
private putInQuotes;
parse(): string;
private beginNewLine;
}
export interface BaseCreatorBeans {
downloader: Downloader;
gridSerializer: GridSerializer;
gridOptionsWrapper: GridOptionsWrapper;
}
export declare abstract class BaseCreator<T, S extends GridSerializingSession<T>, P extends ExportParams<T>> {
private beans;
protected setBeans(beans: BaseCreatorBeans): void;
export(userParams?: P): string;
getData(params?: P): string;
private getMergedParamsAndData;
private mergeDefaultParams;
protected packageFile(data: string): Blob;
abstract createSerializingSession(params?: P): S;
abstract getMimeType(): string;
abstract getDefaultFileName(): string;
abstract getDefaultFileExtension(): string;
abstract isExportSuppressed(): boolean;
}
import { CsvCustomContent, CsvExportParams, GridOptionsWrapper, ICsvCreator } from "@ag-grid-community/core";
import { BaseCreator } from "./baseCreator";
import { CsvSerializingSession } from "./sessions/csvSerializingSession";
export declare class CsvCreator extends BaseCreator<CsvCustomContent, CsvSerializingSession, CsvExportParams> implements ICsvCreator {

@@ -46,0 +5,0 @@ private columnController;

@@ -20,165 +20,5 @@ var __extends = (this && this.__extends) || (function () {

};
import { _, Autowired, Bean, Constants, PostConstruct } from "@ag-grid-community/core";
import { BaseGridSerializingSession } from "./gridSerializer";
var LINE_SEPARATOR = '\r\n';
var CsvSerializingSession = /** @class */ (function (_super) {
__extends(CsvSerializingSession, _super);
function CsvSerializingSession(config) {
var _this = _super.call(this, config) || this;
_this.isFirstLine = true;
_this.result = '';
var suppressQuotes = config.suppressQuotes, columnSeparator = config.columnSeparator;
_this.suppressQuotes = suppressQuotes;
_this.columnSeparator = columnSeparator;
return _this;
}
CsvSerializingSession.prototype.addCustomContent = function (content) {
var _this = this;
if (!content) {
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;
}
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 () {
this.beginNewLine();
return {
onColumn: this.onNewHeaderGroupingRowColumn.bind(this)
};
};
CsvSerializingSession.prototype.onNewHeaderGroupingRowColumn = function (header, index, span) {
if (index != 0) {
this.result += this.columnSeparator;
}
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("");
}
};
CsvSerializingSession.prototype.onNewHeaderRow = function () {
this.beginNewLine();
return {
onColumn: this.onNewHeaderRowColumn.bind(this)
};
};
CsvSerializingSession.prototype.onNewHeaderRowColumn = function (column, index, node) {
if (index != 0) {
this.result += this.columnSeparator;
}
this.result += this.putInQuotes(this.extractHeaderValue(column));
};
CsvSerializingSession.prototype.onNewBodyRow = function () {
this.beginNewLine();
return {
onColumn: this.onNewBodyRowColumn.bind(this)
};
};
CsvSerializingSession.prototype.onNewBodyRowColumn = function (column, index, node) {
if (index != 0) {
this.result += this.columnSeparator;
}
this.result += this.putInQuotes(this.extractRowCellValue(column, index, Constants.EXPORT_TYPE_CSV, node));
};
CsvSerializingSession.prototype.putInQuotes = function (value) {
if (this.suppressQuotes) {
return value;
}
if (value === null || value === undefined) {
return '""';
}
var stringValue;
if (typeof value === 'string') {
stringValue = value;
}
else if (typeof value.toString === 'function') {
stringValue = value.toString();
}
else {
console.warn('unknown value type during csv conversion');
stringValue = '';
}
// replace each " with "" (ie two sets of double quotes is how to do double quotes in csv)
var valueEscaped = stringValue.replace(/"/g, "\"\"");
return '"' + valueEscaped + '"';
};
CsvSerializingSession.prototype.parse = function () {
return this.result;
};
CsvSerializingSession.prototype.beginNewLine = function () {
if (!this.isFirstLine) {
this.result += LINE_SEPARATOR;
}
this.isFirstLine = false;
};
return CsvSerializingSession;
}(BaseGridSerializingSession));
export { CsvSerializingSession };
var BaseCreator = /** @class */ (function () {
function BaseCreator() {
}
BaseCreator.prototype.setBeans = function (beans) {
this.beans = beans;
};
BaseCreator.prototype.export = function (userParams) {
if (this.isExportSuppressed()) {
console.warn("ag-grid: Export cancelled. Export is not allowed as per your configuration.");
return '';
}
var _a = this.getMergedParamsAndData(userParams), mergedParams = _a.mergedParams, data = _a.data;
var fileNamePresent = mergedParams && mergedParams.fileName && mergedParams.fileName.length !== 0;
var fileName = fileNamePresent ? mergedParams.fileName : this.getDefaultFileName();
if (fileName.indexOf(".") === -1) {
fileName = fileName + "." + this.getDefaultFileExtension();
}
this.beans.downloader.download(fileName, this.packageFile(data));
return data;
};
BaseCreator.prototype.getData = function (params) {
return this.getMergedParamsAndData(params).data;
};
BaseCreator.prototype.getMergedParamsAndData = function (userParams) {
var mergedParams = this.mergeDefaultParams(userParams);
var data = this.beans.gridSerializer.serialize(this.createSerializingSession(mergedParams), mergedParams);
return { mergedParams: mergedParams, data: data };
};
BaseCreator.prototype.mergeDefaultParams = function (userParams) {
var baseParams = this.beans.gridOptionsWrapper.getDefaultExportParams();
var params = {};
_.assign(params, baseParams);
_.assign(params, userParams);
return params;
};
BaseCreator.prototype.packageFile = function (data) {
return new Blob(["\ufeff", data], {
type: window.navigator.msSaveOrOpenBlob ? this.getMimeType() : 'octet/stream'
});
};
return BaseCreator;
}());
export { BaseCreator };
import { Autowired, Bean, PostConstruct } from "@ag-grid-community/core";
import { BaseCreator } from "./baseCreator";
import { CsvSerializingSession } from "./sessions/csvSerializingSession";
var CsvCreator = /** @class */ (function (_super) {

@@ -185,0 +25,0 @@ __extends(CsvCreator, _super);

@@ -1,55 +0,3 @@

import { Column, ColumnController, ColumnGroupChild, ExportParams, GridOptionsWrapper, ProcessCellForExportParams, ProcessGroupHeaderForExportParams, ProcessRowGroupForExportParams, ProcessHeaderForExportParams, RowNode, ValueService, BeanStub } from "@ag-grid-community/core";
/**
* This interface works in conjunction with the GridSerializer. When serializing a grid, an instance that implements this interface
* must be passed in, the serializer will call back to the provided methods and finally call to parse to obtain the final result
* of the serialization.
*/
export interface GridSerializingSession<T> {
prepare(columnsToExport: Column[]): void;
onNewHeaderGroupingRow(): RowSpanningAccumulator;
onNewHeaderRow(): RowAccumulator;
onNewBodyRow(): RowAccumulator;
addCustomContent(customContent: T): void;
/**
* FINAL RESULT
*/
parse(): string;
}
export interface RowAccumulator {
onColumn(column: Column, index: number, node?: RowNode): void;
}
export interface RowSpanningAccumulator {
onColumn(header: string, index: number, span: number): void;
}
export interface GridSerializingParams {
columnController: ColumnController;
valueService: ValueService;
gridOptionsWrapper: GridOptionsWrapper;
processCellCallback?: (params: ProcessCellForExportParams) => string;
processHeaderCallback?: (params: ProcessHeaderForExportParams) => string;
processGroupHeaderCallback?: (params: ProcessGroupHeaderForExportParams) => string;
processRowGroupCallback?: (params: ProcessRowGroupForExportParams) => string;
}
export declare abstract class BaseGridSerializingSession<T> implements GridSerializingSession<T> {
columnController: ColumnController;
valueService: ValueService;
gridOptionsWrapper: GridOptionsWrapper;
processCellCallback?: (params: ProcessCellForExportParams) => string;
processHeaderCallback?: (params: ProcessHeaderForExportParams) => string;
processGroupHeaderCallback?: (params: ProcessGroupHeaderForExportParams) => string;
processRowGroupCallback?: (params: ProcessRowGroupForExportParams) => string;
private groupColumns;
constructor(config: GridSerializingParams);
abstract addCustomContent(customContent: T): void;
abstract onNewHeaderGroupingRow(): RowSpanningAccumulator;
abstract onNewHeaderRow(): RowAccumulator;
abstract onNewBodyRow(): RowAccumulator;
abstract parse(): string;
prepare(columnsToExport: Column[]): void;
extractHeaderValue(column: Column): string;
extractRowCellValue(column: Column, index: number, type: string, node: RowNode): any;
private getHeaderName;
private createValueForGroupNode;
private processCell;
}
import { BeanStub, ColumnGroupChild, ExportParams, ProcessGroupHeaderForExportParams } from "@ag-grid-community/core";
import { GridSerializingSession } from "./interfaces";
export declare class GridSerializer extends BeanStub {

@@ -61,3 +9,2 @@ private displayedGroupCreator;

private selectionController;
private columnFactory;
serialize<T>(gridSerializingSession: GridSerializingSession<T>, params?: ExportParams<T>): string;

@@ -64,0 +11,0 @@ recursivelyAddHeaderGroups<T>(displayedGroups: ColumnGroupChild[], gridSerializingSession: GridSerializingSession<T>, processGroupHeaderCallback: ProcessGroupHeaderCallback | undefined): void;

@@ -20,89 +20,3 @@ var __extends = (this && this.__extends) || (function () {

};
import { _, Autowired, Bean, ColumnGroup, Constants, GroupInstanceIdCreator, BeanStub } from "@ag-grid-community/core";
var BaseGridSerializingSession = /** @class */ (function () {
function BaseGridSerializingSession(config) {
this.groupColumns = [];
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;
this.valueService = valueService;
this.gridOptionsWrapper = gridOptionsWrapper;
this.processCellCallback = processCellCallback;
this.processHeaderCallback = processHeaderCallback;
this.processGroupHeaderCallback = processGroupHeaderCallback;
this.processRowGroupCallback = processRowGroupCallback;
}
BaseGridSerializingSession.prototype.prepare = function (columnsToExport) {
this.groupColumns = _.filter(columnsToExport, function (col) { return !!col.getColDef().showRowGroup; });
};
BaseGridSerializingSession.prototype.extractHeaderValue = function (column) {
var value = this.getHeaderName(this.processHeaderCallback, column);
return value != null ? value : '';
};
BaseGridSerializingSession.prototype.extractRowCellValue = function (column, index, type, node) {
// we render the group summary text e.g. "-> Parent -> Child"...
var groupIndex = this.gridOptionsWrapper.isGroupMultiAutoColumn() ? node.rowGroupIndex : 0;
var renderGroupSummaryCell =
// on group rows
node && node.group
&& (
// in the group column if groups appear in regular grid cells
index === groupIndex && this.groupColumns.indexOf(column) !== -1
// 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 (renderGroupSummaryCell) {
valueForCell = this.createValueForGroupNode(node);
}
else {
valueForCell = this.valueService.getValue(column, node);
}
var value = this.processCell(node, column, valueForCell, this.processCellCallback, type);
return value != null ? value : '';
};
BaseGridSerializingSession.prototype.getHeaderName = function (callback, column) {
if (callback) {
return callback({
column: column,
api: this.gridOptionsWrapper.getApi(),
columnApi: this.gridOptionsWrapper.getColumnApi(),
context: this.gridOptionsWrapper.getContext()
});
}
return this.columnController.getDisplayNameForColumn(column, 'csv', true);
};
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];
if (!this.gridOptionsWrapper.isGroupMultiAutoColumn()) {
while (node.parent) {
node = node.parent;
keys.push(node.key);
}
}
return keys.reverse().join(' -> ');
};
BaseGridSerializingSession.prototype.processCell = function (rowNode, column, value, processCellCallback, type) {
if (processCellCallback) {
return processCellCallback({
column: column,
node: rowNode,
value: value,
api: this.gridOptionsWrapper.getApi(),
columnApi: this.gridOptionsWrapper.getColumnApi(),
context: this.gridOptionsWrapper.getContext(),
type: type
});
}
return value;
};
return BaseGridSerializingSession;
}());
export { BaseGridSerializingSession };
import { Autowired, Bean, BeanStub, ColumnGroup, Constants, GroupInstanceIdCreator, _ } from "@ag-grid-community/core";
var GridSerializer = /** @class */ (function (_super) {

@@ -116,7 +30,9 @@ __extends(GridSerializer, _super);

var rowSkipper = params.shouldRowBeSkipped || (function () { return false; });
var api = this.gridOptionsWrapper.getApi();
var columnApi = this.gridOptionsWrapper.getColumnApi();
var skipSingleChildrenGroup = this.gridOptionsWrapper.isGroupRemoveSingleChildren();
var skipLowestSingleChildrenGroup = this.gridOptionsWrapper.isGroupRemoveLowestSingleChildren();
var context = this.gridOptionsWrapper.getContext();
var gridOptionsWrapper = this.gridOptionsWrapper;
var api = gridOptionsWrapper.getApi();
var columnApi = gridOptionsWrapper.getColumnApi();
var skipSingleChildrenGroup = gridOptionsWrapper.isGroupRemoveSingleChildren();
var skipLowestSingleChildrenGroup = gridOptionsWrapper.isGroupRemoveLowestSingleChildren();
var hideOpenParents = gridOptionsWrapper.isGroupHideOpenParents();
var context = gridOptionsWrapper.getContext();
// when in pivot mode, we always render cols on screen, never 'all columns'

@@ -132,3 +48,3 @@ var isPivotMode = this.columnController.isPivotMode();

// add auto group column for tree data
columnsToExport = this.gridOptionsWrapper.isTreeData() ?
columnsToExport = gridOptionsWrapper.isTreeData() ?
this.columnController.getGridColumns([Constants.GROUP_AUTO_COLUMN_ID]) : [];

@@ -157,9 +73,12 @@ columnsToExport = columnsToExport.concat(this.columnController.getAllPrimaryColumns() || []);

this.pinnedRowModel.forEachPinnedTopRow(processRow);
var rowModel = this.rowModel;
var clientSideRowModel = this.rowModel;
if (isPivotMode) {
if (this.rowModel.forEachPivotNode) {
this.rowModel.forEachPivotNode(processRow);
// @ts-ignore - ignore tautology below as we are using it to check if it's clientSideRowModel
if (clientSideRowModel.forEachPivotNode) {
clientSideRowModel.forEachPivotNode(processRow);
}
else {
//Must be enterprise, so we can just loop through all the nodes
this.rowModel.forEachNode(processRow);
// n=must be enterprise, so we can just loop through all the nodes
rowModel.forEachNode(processRow);
}

@@ -172,3 +91,3 @@ }

// onlySelectedNonStandardModel: if user wants selected in non standard row model
// (eg viewport) then again rowmodel cannot be used, so need to use selected instead.
// (eg viewport) then again RowModel cannot be used, so need to use selected instead.
if (params.onlySelectedAllPages || onlySelectedNonStandardModel) {

@@ -185,6 +104,6 @@ var selectedNodes = this.selectionController.getSelectedNodes();

if (rowModelNormal) {
this.rowModel.forEachNodeAfterFilterAndSort(processRow);
clientSideRowModel.forEachNodeAfterFilterAndSort(processRow);
}
else {
this.rowModel.forEachNode(processRow);
rowModel.forEachNode(processRow);
}

@@ -200,3 +119,3 @@ }

var shouldSkipCurrentGroup = node.allChildrenCount === 1 && (skipSingleChildrenGroup || shouldSkipLowestGroup);
if (node.group && (params.skipGroups || shouldSkipCurrentGroup)) {
if (node.group && (params.skipGroups || shouldSkipCurrentGroup || hideOpenParents)) {
return;

@@ -291,5 +210,2 @@ }

], GridSerializer.prototype, "selectionController", void 0);
__decorate([
Autowired('columnFactory')
], GridSerializer.prototype, "columnFactory", void 0);
GridSerializer = __decorate([

@@ -296,0 +212,0 @@ Bean("gridSerializer")

@@ -1,6 +0,9 @@

export { CsvExportModule } from "./csvExportModule";
export { BaseCreator, CsvCreator } from "./csvExport/csvCreator";
export { Downloader } from "./csvExport/downloader";
export { GridSerializer, RowType, RowSpanningAccumulator, BaseGridSerializingSession, GridSerializingParams, RowAccumulator } from "./csvExport/gridSerializer";
export { ZipContainer } from "./csvExport/zipContainer";
export { XmlFactory } from "./csvExport/xmlFactory";
export { BaseCreator } from './csvExport/baseCreator';
export { BaseGridSerializingSession } from './csvExport/sessions/baseGridSerializingSession';
export { CsvCreator } from './csvExport/csvCreator';
export { CsvExportModule } from './csvExportModule';
export { Downloader } from './csvExport/downloader';
export { GridSerializer, RowType } from './csvExport/gridSerializer';
export { RowSpanningAccumulator, GridSerializingParams, RowAccumulator } from './csvExport/interfaces';
export { XmlFactory } from './csvExport/xmlFactory';
export { ZipContainer } from './csvExport/zipContainer';

@@ -1,6 +0,8 @@

export { CsvExportModule } from "./csvExportModule";
export { BaseCreator, CsvCreator } from "./csvExport/csvCreator";
export { Downloader } from "./csvExport/downloader";
export { GridSerializer, RowType, BaseGridSerializingSession } from "./csvExport/gridSerializer";
export { ZipContainer } from "./csvExport/zipContainer";
export { XmlFactory } from "./csvExport/xmlFactory";
export { BaseCreator } from './csvExport/baseCreator';
export { BaseGridSerializingSession } from './csvExport/sessions/baseGridSerializingSession';
export { CsvCreator } from './csvExport/csvCreator';
export { CsvExportModule } from './csvExportModule';
export { Downloader } from './csvExport/downloader';
export { GridSerializer, RowType } from './csvExport/gridSerializer';
export { XmlFactory } from './csvExport/xmlFactory';
export { ZipContainer } from './csvExport/zipContainer';
{
"name": "@ag-grid-community/csv-export",
"version": "25.0.1",
"version": "25.1.0",
"description": "Advanced Data Grid / Data Table supporting Javascript / React / AngularJS / Web Components",

@@ -45,3 +45,3 @@ "main": "./dist/cjs/main.js",

"dependencies": {
"@ag-grid-community/core": "~25.0.0"
"@ag-grid-community/core": "~25.1.0"
},

@@ -48,0 +48,0 @@ "devDependencies": {

@@ -1,2 +0,2 @@

![alt text](./github-banner.png "ag-Grid")
![alt text](./github-banner.png "AG Grid")

@@ -7,10 +7,10 @@ [![CDNJS](https://img.shields.io/cdnjs/v/ag-grid.svg)](https://cdnjs.com/libraries/ag-grid)

# ag-Grid
# AG Grid
ag-Grid is a fully-featured and highly customizable JavaScript data grid.
It delivers [outstanding performance](https://www.ag-grid.com/example.php?utm_source=@ag-grid-community/csv-export-readme&utm_medium=repository&utm_campaign=github#/performance/1), has no third-party dependencies and [integrates smoothly with all major JavaScript frameworks](https://www.ag-grid.com/documentation/javascript/getting-started/?utm_source=@ag-grid-community/csv-export-readme&utm_medium=repository&utm_campaign=github).
AG Grid is a fully-featured and highly customizable JavaScript data grid.
It delivers [outstanding performance](https://www.ag-grid.com/example.php?utm_source=@ag-grid-community/csv-export-readme&utm_medium=repository&utm_campaign=github), has no third-party dependencies and [integrates smoothly with all major JavaScript frameworks](https://www.ag-grid.com/documentation/javascript/getting-started/?utm_source=@ag-grid-community/csv-export-readme&utm_medium=repository&utm_campaign=github).
Here's how our grid looks with multiple filters and grouping enabled:
![alt text](./github-grid-demo.jpg "ag-Grid demo")
![alt text](./github-grid-demo.jpg "AG Grid demo")

@@ -26,3 +26,3 @@ ## Features

Here are some of the features that make ag-Grid stand out:
Here are some of the features that make AG Grid stand out:

@@ -119,3 +119,3 @@ * Grouping / Aggregation *

ag-Grid is developed by a team of co-located developers in London. If you want to join the team check out our [jobs board](https://www.ag-grid.com/ag-grid-jobs-board/?utm_source=@ag-grid-community/csv-export-readme&utm_medium=repository&utm_campaign=github) or send your application to info@ag-grid.com.
AG Grid is developed by a team of co-located developers in London. If you want to join the team check out our [jobs board](https://www.ag-grid.com/ag-grid-jobs-board/?utm_source=@ag-grid-community/csv-export-readme&utm_medium=repository&utm_campaign=github) or send your application to info@ag-grid.com.

@@ -122,0 +122,0 @@ ## License

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc