columnSummary Question

Tags: #<Tag:0x00007efc6ad52c68>

Hello Im trying to set up my cols sums to write out to a final total row. I want to take a sub total line that will be dynamic and add those sub totals on the final total line.

how can I accomplish this with the columnSummary setting.

I want to total the 2 blue lines on the final yellow line. The blue lines are part of a dynamic group so there could be many, or just one. Is this possible?
14%20PM

here is a code snippet that Im using right now.
for (let i = 0; i < nestedRowsCache.levels[1].length; i++) {
if (nestedRowsCache.levels[1][i].RT !== ‘Total3’)
continue

            console.log(nestedRowsCache.levels[1][i])
            console.log(getRowIndex(nestedRowsCache.levels[0][nestedRowsCache.levels[0].length -1]))

            for (let x = colOffset; x < this.hot.countCols(); x++) {
                grandTotalEndpoint = {};

                grandTotalEndpoint.type = 'sum';
                grandTotalEndpoint.destinationRow = getRowIndex(nestedRowsCache.levels[0][nestedRowsCache.levels[0].length - 1]);
                grandTotalEndpoint.destinationColumn = x;
                grandTotalEndpoint.ranges = [];
                //grandTotalEndpoint.customFunction = (endpoint) => {
                //    console.log(nestedRowsCache.levels[1][i])
                //    return 10;
                //}
                console.log(nestedRowsCache.levels[1][i])
                grandTotalEndpoint.ranges.push([
                    [getRowIndex(nestedRowsCache.levels[1][i])]
                ]);

                endpoints.push(grandTotalEndpoint);
                headCountTempEndpoint = null;
            }
        }

Hey @damien1

Here’s a demo based on the one from the docs but with the total SUM attached https://jsfiddle.net/zu7xgr06/

I just pushed another element to the endpoints array and added an object to the main data to hold the value.

Do you need anything more than that?

This doesn’t quite work for me, your solution is only summing the values in white, whereas I only want to sum the values in blue.

33%20AM

my data is structured as this
[
{data: ‘somval’, __children[{data: ‘vals’}]},
{data: ‘Grand Totals’} //no children
]

In this case I think that the Formulas might be a better pick. Have you tried that?

I have not, can you expand on how I would use that?

The Formulas plugin is base to SUM some specific cells. Here https://handsontable.com/docs/javascript-data-grid/formula-calculation/ you can read more about it.

To enable formulas you need to add this line to the initialization (or update) settings

formulas: { engine: HyperFormula},

and import the HyperFormula if you use wrappers.

Then just pass the formula known from Excel to the cell. In this case if you want to Sum row no1 and 5 it will be value: '=A1 + A5'. And then when data changes, rows are added or deleted you just update that coordinates with setDataAtCell() in corresponding hooks like