diff --git a/examples/vite-demo-vanilla-bundle/src/examples/example19.html b/examples/vite-demo-vanilla-bundle/src/examples/example19.html
index 95581f7d2..759f9ac72 100644
--- a/examples/vite-demo-vanilla-bundle/src/examples/example19.html
+++ b/examples/vite-demo-vanilla-bundle/src/examples/example19.html
@@ -18,8 +18,10 @@
- Grid - using enableExcelCopyBuffer
which uses SlickCellSelectionModel
- The complete first row and the cells C - E of the second row are not allowing to paste values.
+ Grid - using enableExcelCopyBuffer
which uses SlickCellSelectionModel
+ The complete first row and the cells C - E of the second row are not allowing to paste values.
+ Additionally the columns are configured to exportWithFormatter
and a custom formatter that renders the cells coordinates or value if available.
+ When selecting one or more cells and pressing CTRL + C, the ExcelCopyBuffer will be filled with the formatter outputs of the selected cells.
{
+ if (value !== null && value !== undefined) {
+ return value;
+ }
+
+ return `${row + 1}:${cell + 1}`;
+ },
width: 60,
editor: { model: Editors.text }
});
diff --git a/packages/common/src/extensions/slickCellExcelCopyManager.ts b/packages/common/src/extensions/slickCellExcelCopyManager.ts
index a1fa1a736..664811206 100644
--- a/packages/common/src/extensions/slickCellExcelCopyManager.ts
+++ b/packages/common/src/extensions/slickCellExcelCopyManager.ts
@@ -142,13 +142,13 @@ export class SlickCellExcelCopyManager {
clipboardCommandHandler: (editCommand: EditCommand) => {
this._undoRedoBuffer.queueAndExecuteCommand.call(this._undoRedoBuffer, editCommand);
},
- dataItemColumnValueExtractor: (item: any, columnDef: Column) => {
+ dataItemColumnValueExtractor: (item: any, columnDef: Column, row: number = 0, cell: number = 0) => {
// when grid or cell is not editable, we will possibly evaluate the Formatter if it was passed
// to decide if we evaluate the Formatter, we will use the same flag from Export which is "exportWithFormatter"
if (!this.gridOptions.editable || !columnDef.editor) {
const isEvaluatingFormatter = (columnDef.exportWithFormatter !== undefined) ? columnDef.exportWithFormatter : (this.gridOptions.textExportOptions?.exportWithFormatter);
if (columnDef.formatter && isEvaluatingFormatter) {
- const formattedOutput = columnDef.formatter(0, 0, item[columnDef.field], columnDef, item, this._grid);
+ const formattedOutput = columnDef.formatter(row, cell, item[columnDef.field], columnDef, item, this._grid);
const cellResult = isPrimitiveOrHTML(formattedOutput) ? formattedOutput : (formattedOutput as FormatterResultWithHtml).html || (formattedOutput as FormatterResultWithText).text;
if (columnDef.sanitizeDataExport || (this.gridOptions.textExportOptions?.sanitizeDataExport)) {
const outputString = (cellResult instanceof HTMLElement) ? cellResult.innerHTML : cellResult as string;
diff --git a/packages/common/src/extensions/slickCellExternalCopyManager.ts b/packages/common/src/extensions/slickCellExternalCopyManager.ts
index ebb73d0f5..d22872538 100644
--- a/packages/common/src/extensions/slickCellExternalCopyManager.ts
+++ b/packages/common/src/extensions/slickCellExternalCopyManager.ts
@@ -115,9 +115,9 @@ export class SlickCellExternalCopyManager {
return getHtmlStringOutput(columnDef.name || '', 'innerHTML');
}
- getDataItemValueForColumn(item: any, columnDef: Column, event: SlickEventData) {
+ getDataItemValueForColumn(item: any, columnDef: Column, row: number, cell: number, event: SlickEventData) {
if (typeof this._addonOptions.dataItemColumnValueExtractor === 'function') {
- const val = this._addonOptions.dataItemColumnValueExtractor(item, columnDef) as string | HTMLElement;
+ const val = this._addonOptions.dataItemColumnValueExtractor(item, columnDef, row, cell) as string | HTMLElement;
if (val) {
return (val instanceof HTMLElement) ? stripTags(val.innerHTML) : val;
}
@@ -433,7 +433,7 @@ export class SlickCellExternalCopyManager {
? stripTags((columns[j].name as HTMLElement).innerHTML)
: columns[j].name as string;
if (colName.length > 0 && !columns[j].hidden) {
- clipTextCells.push(this.getDataItemValueForColumn(dt, columns[j], e));
+ clipTextCells.push(this.getDataItemValueForColumn(dt, columns[j], i, j, e));
}
}
clipTextRows.push(clipTextCells.join('\t'));
diff --git a/packages/common/src/interfaces/excelCopyBufferOption.interface.ts b/packages/common/src/interfaces/excelCopyBufferOption.interface.ts
index 09e2002a0..5cc7d89fa 100644
--- a/packages/common/src/interfaces/excelCopyBufferOption.interface.ts
+++ b/packages/common/src/interfaces/excelCopyBufferOption.interface.ts
@@ -17,7 +17,7 @@ export interface ExcelCopyBufferOption {
copiedCellStyleLayerKey?: string;
/** option to specify a custom column value extractor function */
- dataItemColumnValueExtractor?: (item: any, columnDef: Column) => string | HTMLElement | DocumentFragment | FormatterResultWithHtml | FormatterResultWithText | null;
+ dataItemColumnValueExtractor?: (item: any, columnDef: Column, row?: number, cell?: number) => string | HTMLElement | DocumentFragment | FormatterResultWithHtml | FormatterResultWithText | null;
/** option to specify a custom column value setter function */
dataItemColumnValueSetter?: (item: any, columnDef: Column, value: any) => string | FormatterResultWithHtml | FormatterResultWithText | null;