From b2a37b6ed894a771011cd1f767dfeef47e03ebd8 Mon Sep 17 00:00:00 2001 From: Josemi Date: Wed, 25 Oct 2023 13:16:27 +0200 Subject: [PATCH] wc: fix providing custom data to columns extensions #TASK-5066 --- src/webcomponents/extensions-manager.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/webcomponents/extensions-manager.js b/src/webcomponents/extensions-manager.js index 79c165008d..9a5c920812 100644 --- a/src/webcomponents/extensions-manager.js +++ b/src/webcomponents/extensions-manager.js @@ -73,8 +73,10 @@ export default { // Returns a list of custom columns for the specified component // @param {array} columns - An array of columns where new columns will be injected // @param {string} componentId - ID of the component where this new column will be injected + // @param {function} checkColumnVisible: function to determine if column is visible or not + // @param {function} getData: function to obtain custom data for columns // @return {array} columns - a list of columns configurations - injectColumns(columns, componentId, checkColumnVisible, data) { + injectColumns(columns, componentId, checkColumnVisible, getData) { // We need to check if we are in a single or multiple row levels const hasGroupedRows = columns.length === 2 && (Array.isArray(columns[0]) && Array.isArray(columns[1])); this.getByType(this.TYPES.COLUMN) @@ -84,12 +86,12 @@ export default { [newColumns].flat().forEach(newColumn => { const group = hasGroupedRows ? columns[index] : columns; const position = newColumn.position ?? group.length; - const columnData = data[extension.id] || {}; const config = { ...newColumn.config, // We need to overwrite the formatter to provide custom data of this columns formatter: (value, row, index) => { - return newColumn.config.formatter(value, row, index, columnData); + const data = typeof getData === "function" ? getData() : {}; + return newColumn.config.formatter(value, row, index, data?.[extension.id]); }, }; // check if we have provided a function to check if column is visible