diff --git a/src/js/modules/ColumnCalcs/ColumnCalcs.js b/src/js/modules/ColumnCalcs/ColumnCalcs.js index 2d706004b..d745dc070 100644 --- a/src/js/modules/ColumnCalcs/ColumnCalcs.js +++ b/src/js/modules/ColumnCalcs/ColumnCalcs.js @@ -411,7 +411,7 @@ export default class ColumnCalcs extends Module{ if(hasDataTreeColumnCalcs && row.modules.dataTree?.open){ this.rowsToData(dataTree.getFilteredTreeChildren(row)).forEach(dataRow =>{ - data.push(row); + data.push(dataRow); }); } }); @@ -583,4 +583,4 @@ export default class ColumnCalcs extends Module{ } } } -} \ No newline at end of file +} diff --git a/test/unit/modules/ColumnCalcs.spec.js b/test/unit/modules/ColumnCalcs.spec.js index 6ef0132cc..621cd7440 100644 --- a/test/unit/modules/ColumnCalcs.spec.js +++ b/test/unit/modules/ColumnCalcs.spec.js @@ -147,6 +147,45 @@ describe('ColumnCalcs', function(){ expect(data[1].name).toBe("Jane"); }); + test('rowsToData includes data tree child row data when child calcs are enabled', function(){ + const childRows = [ + {getData: function() { return {id: 2, value: 20}; }, modules: {}}, + {getData: function() { return {id: 3, value: 30}; }, modules: {}}, + ]; + const parentRow = { + getData: function() { return {id: 1, value: 10}; }, + modules: { + dataTree: { + open: true, + }, + }, + }; + + const mockThis = { + rowsToData: ColumnCalcs.prototype.rowsToData, + table: { + options: { + dataTree: true, + dataTreeChildColumnCalcs: true, + }, + modules: { + dataTree: { + getFilteredTreeChildren: jest.fn(() => childRows), + }, + }, + }, + }; + + const data = ColumnCalcs.prototype.rowsToData.call(mockThis, [parentRow]); + + expect(data).toEqual([ + {id: 1, value: 10}, + {id: 2, value: 20}, + {id: 3, value: 30}, + ]); + expect(mockThis.table.modules.dataTree.getFilteredTreeChildren).toHaveBeenCalledWith(parentRow); + }); + test('generateRowData creates calculation results', function(){ // Create mock data const data = [ @@ -266,4 +305,4 @@ describe('ColumnCalcs', function(){ afterAll(() => { Module.prototype.registerTableOption = originalRegisterTableOption; Module.prototype.registerColumnOption = originalRegisterColumnOption; -}); \ No newline at end of file +});