diff --git a/packages/common/src/formatters/treeExportFormatter.ts b/packages/common/src/formatters/treeExportFormatter.ts index d000fc5dc..18fc3080f 100644 --- a/packages/common/src/formatters/treeExportFormatter.ts +++ b/packages/common/src/formatters/treeExportFormatter.ts @@ -1,6 +1,6 @@ import { Constants } from '../constants'; import { Formatter } from './../interfaces/index'; -import { addWhiteSpaces, getDescendantProperty, sanitizeHtmlToText, } from '../services/utilities'; +import { addWhiteSpaces, getCellValueFromQueryFieldGetter, sanitizeHtmlToText, } from '../services/utilities'; import { parseFormatterWhenExist } from './formatterUtilities'; /** Formatter that must be use with a Tree Data column */ @@ -17,14 +17,9 @@ export const treeExportFormatter: Formatter = (row, cell, value, columnDef, data const groupExpandedSymbol = gridOptions?.excelExportOptions?.groupExpandedSymbol ?? '⮟'; let outputValue = value; - if (typeof columnDef.queryFieldNameGetterFn === 'function') { - const fieldName = columnDef.queryFieldNameGetterFn(dataContext); - if (fieldName?.indexOf('.') >= 0) { - outputValue = getDescendantProperty(dataContext, fieldName); - } else { - outputValue = dataContext.hasOwnProperty(fieldName) ? dataContext[fieldName] : value; - } - } + // when a queryFieldNameGetterFn is defined, then get the value from that getter callback function + outputValue = getCellValueFromQueryFieldGetter(columnDef, dataContext, value); + if (outputValue === null || outputValue === undefined || dataContext === undefined) { return ''; } diff --git a/packages/common/src/formatters/treeFormatter.ts b/packages/common/src/formatters/treeFormatter.ts index 8226afa4e..080f46528 100644 --- a/packages/common/src/formatters/treeFormatter.ts +++ b/packages/common/src/formatters/treeFormatter.ts @@ -1,7 +1,7 @@ import { Constants } from '../constants'; import { Formatter } from './../interfaces/index'; import { parseFormatterWhenExist } from './formatterUtilities'; -import { getDescendantProperty, sanitizeTextByAvailableSanitizer } from '../services/utilities'; +import { getCellValueFromQueryFieldGetter, sanitizeTextByAvailableSanitizer } from '../services/utilities'; /** Formatter that must be use with a Tree Data column */ export const treeFormatter: Formatter = (row, cell, value, columnDef, dataContext, grid) => { @@ -13,14 +13,9 @@ export const treeFormatter: Formatter = (row, cell, value, columnDef, dataContex const treeLevelPropName = treeDataOptions?.levelPropName ?? Constants.treeDataProperties.TREE_LEVEL_PROP; let outputValue = value; - if (typeof columnDef.queryFieldNameGetterFn === 'function') { - const fieldName = columnDef.queryFieldNameGetterFn(dataContext); - if (fieldName?.indexOf('.') >= 0) { - outputValue = getDescendantProperty(dataContext, fieldName); - } else { - outputValue = dataContext.hasOwnProperty(fieldName) ? dataContext[fieldName] : value; - } - } + // when a queryFieldNameGetterFn is defined, then get the value from that getter callback function + outputValue = getCellValueFromQueryFieldGetter(columnDef, dataContext, value); + if (outputValue === null || outputValue === undefined || dataContext === undefined) { return ''; } diff --git a/packages/common/src/plugins/contextMenu.plugin.ts b/packages/common/src/plugins/contextMenu.plugin.ts index 838025cef..72862fbdb 100644 --- a/packages/common/src/plugins/contextMenu.plugin.ts +++ b/packages/common/src/plugins/contextMenu.plugin.ts @@ -10,7 +10,7 @@ import { MenuOptionItem, SlickEventHandler, } from '../interfaces/index'; -import { getDescendantProperty, getTranslationPrefix, } from '../services/index'; +import { getCellValueFromQueryFieldGetter, getTranslationPrefix, } from '../services/index'; import { exportWithFormatterWhenDefined } from '../formatters/formatterUtilities'; import { ExtensionUtility } from '../extensions/extensionUtility'; import { PubSubService } from '../services/pubSub.service'; @@ -184,7 +184,7 @@ export class ContextMenuPlugin extends MenuFromCellBaseClass { const columnDef = args?.column as Column; const dataContext = args?.dataContext; if (typeof columnDef.queryFieldNameGetterFn === 'function') { - const cellValue = this.getCellValueFromQueryFieldGetter(columnDef, dataContext); + const cellValue = getCellValueFromQueryFieldGetter(columnDef, dataContext, ''); if (cellValue !== '' && cellValue !== undefined) { return true; } @@ -397,7 +397,7 @@ export class ContextMenuPlugin extends MenuFromCellBaseClass { let textToCopy = exportWithFormatterWhenDefined(row, cell, columnDef, dataContext, grid, exportOptions); if (typeof columnDef.queryFieldNameGetterFn === 'function') { - textToCopy = this.getCellValueFromQueryFieldGetter(columnDef, dataContext); + textToCopy = getCellValueFromQueryFieldGetter(columnDef, dataContext, ''); } // create fake