diff --git a/addons/spreadsheet/static/src/pivot/pivot_model.js b/addons/spreadsheet/static/src/pivot/pivot_model.js index 2659ef9b862..919666c9b94 100644 --- a/addons/spreadsheet/static/src/pivot/pivot_model.js +++ b/addons/spreadsheet/static/src/pivot/pivot_model.js @@ -17,6 +17,8 @@ const { toString, toNumber, toBoolean } = spreadsheet.helpers; /** * @typedef {import("@spreadsheet/data_sources/metadata_repository").Field} Field + * @typedef {import("@spreadsheet/pivot/pivot_table").Row} Row + * @typedef {import("@spreadsheet/pivot/pivot_table").Column} Column * * @typedef {Object} PivotMetaData * @property {Array} colGroupBys @@ -545,8 +547,10 @@ export class SpreadsheetPivotModel extends PivotModel { /** * Get the row structure + * @returns {Row[]} */ _getSpreadsheetRows(tree) { + /**@type {Row[]}*/ let rows = []; const group = tree.root; const indent = group.labels.length; @@ -554,7 +558,7 @@ export class SpreadsheetPivotModel extends PivotModel { rows.push({ fields: rowGroupBys.slice(0, indent), - values: [...group.values], + values: group.values.map((val) => val.toString()), indent, }); @@ -568,6 +572,7 @@ export class SpreadsheetPivotModel extends PivotModel { /** * Get the col structure + * @returns {Column[][]} */ _getSpreadsheetCols() { const colGroupBys = this.metaData.fullColGroupBys; @@ -585,7 +590,7 @@ export class SpreadsheetPivotModel extends PivotModel { const leafCount = leafCounts[JSON.stringify(tree.root.values)]; const cell = { fields: colGroupBys.slice(0, rowIndex), - values: [...group.values], + values: group.values.map((val) => val.toString()), width: leafCount * measureCount, }; row.push(cell); diff --git a/addons/spreadsheet/static/src/pivot/pivot_table.js b/addons/spreadsheet/static/src/pivot/pivot_table.js index 69129c8961b..afe3748641c 100644 --- a/addons/spreadsheet/static/src/pivot/pivot_table.js +++ b/addons/spreadsheet/static/src/pivot/pivot_table.js @@ -125,13 +125,6 @@ export class SpreadsheetPivotTable { return this._rows.length; } - getCellFromMeasureRowWithDomain(values) { - const vals = JSON.stringify(values).slice(0, -1); //Remove the last "]" - return this.getMeasureHeaders().find((cell) => - JSON.stringify(cell.values).startsWith(vals) - ); - } - /** * Get the index of the cell in the measure row (i.e. the last one) which * correspond to the given values @@ -140,7 +133,24 @@ export class SpreadsheetPivotTable { */ getColMeasureIndex(values) { const vals = JSON.stringify(values); - return this.getMeasureHeaders().findIndex((cell) => JSON.stringify(cell.values) === vals); + const maxLength = Math.max(...this._cols.map((col) => col.length)); + for (let i = 0; i < maxLength; i++) { + const cellValues = this._cols.map((col) => JSON.stringify((col[i] || {}).values)); + if (cellValues.includes(vals)) { + return i; + } + } + return -1; + } + + /** + * + * @param {number} colIndex + * @param {number} rowIndex + * @returns {Column} + */ + getNextColCell(colIndex, rowIndex) { + return this._cols[rowIndex][colIndex]; } getRowIndex(values) {