Skip to content

Commit

Permalink
[FIX] pivot: update pivot formulas when data set changes
Browse files Browse the repository at this point in the history
Steps to reproduce:
- create a pivot based on a range
- remove the `=PIVOT(1)` formula
- add a few individual `PIVOT.VALUE` or `PIVOT.HEADER` formula
- change values in the range data set
=> the formulas are not updated

closes #4725

Task: 4082765
Signed-off-by: Rémi Rahir (rar) <[email protected]>
  • Loading branch information
LucasLefevre committed Aug 2, 2024
1 parent 40ecd1e commit 5bac40b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/functions/module_lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ export const PIVOT_VALUE = {
const coreDefinition = this.getters.getPivotCoreDefinition(pivotId);

addPivotDependencies(this, coreDefinition);
pivot.init({ reload: pivot.needsReevaluation });
const error = pivot.assertIsValid({ throwOnError: false });
if (error) {
return error;
Expand Down Expand Up @@ -754,6 +755,7 @@ export const PIVOT_HEADER = {
const pivot = this.getters.getPivot(_pivotId);
const coreDefinition = this.getters.getPivotCoreDefinition(_pivotId);
addPivotDependencies(this, coreDefinition);
pivot.init({ reload: pivot.needsReevaluation });
const error = pivot.assertIsValid({ throwOnError: false });
if (error) {
return error;
Expand Down
38 changes: 38 additions & 0 deletions tests/pivots/spreadsheet_pivot/spreadsheet_pivot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1422,4 +1422,42 @@ describe("Spreadsheet arguments parsing", () => {
},
]);
});

test("update PIVOT.VALUE when data set changes", () => {
const grid = {
A1: "Price",
B1: "Customer",
A2: "2",
B2: "Alice",
A3: '=PIVOT.VALUE(1, "Price")',
};
const model = createModelFromGrid(grid);
addPivot(model, "A1:B2", {
columns: [],
rows: [{ name: "Customer" }],
measures: [{ name: "Price", aggregator: "sum" }],
});
expect(getEvaluatedCell(model, "A3").value).toBe(2);
setCellContent(model, "A2", "3");
expect(getEvaluatedCell(model, "A3").value).toBe(3);
});

test("update PIVOT.HEADER when data set changes", () => {
const grid = {
A1: "Price",
B1: "Customer",
A2: "2",
B2: "Alice",
A3: '=PIVOT.HEADER(1, "Customer", "Alice")',
};
const model = createModelFromGrid(grid);
addPivot(model, "A1:B2", {
columns: [],
rows: [{ name: "Customer" }],
measures: [{ name: "Price", aggregator: "sum" }],
});
expect(getEvaluatedCell(model, "A3").value).toBe("Alice");
setCellContent(model, "B2", "Bob");
expect(getEvaluatedCell(model, "A3").value).toBe("");
});
});

0 comments on commit 5bac40b

Please sign in to comment.