columnSummary sums double

Tags: #<Tag:0x00007efc70520c88> #<Tag:0x00007efc70520b20>

I defined 3 summarizing columns:
columnSummary: [
{
destinationRow: 0,
destinationColumn: 9,
reversedRowCoords: true,
type: ‘sum’
},
{
destinationRow: 0,
destinationColumn: 10,
reversedRowCoords: true,
type: ‘sum’
},
{
destinationRow: 0,
destinationColumn: 11,
reversedRowCoords: true,
type: ‘sum’
}],

Then the summary column sums two times the total amount of the values, example:

image

Can you please tell me what I am doing wrong?

My complete code:

function loadhot(parm) {
const data = parm;
//alert(JSON.stringify(dynamicColumns));
var conten = document.getElementById(‘gridBodyTableExcel’);

    HoT = new Handsontable(conten, {
        data,
        height: "110vh",

        colWidths: [40, 80, 80, 390, 100, 100, 100, 50, 80, 70, 70, 70, 50, 50, 50, 50, 50, 50, 50, 50, 50],
        colHeaders: 
          vColHeaders
        ,
        columns: dynamicColumns  ,
        afterChange: function (change, source) {
            if (source === 'loadData') {
                return; //don't save this change
            }
        },
        afterGetColHeader: function (i, TH) {
            if (i > 7) {
                TH.innerHTML = '<div class="header">' + TH.innerHTML + '</div>';
            };
        },
        dropdownMenu: true,
        contextMenu: true,
        multiColumnSorting: true,
        filters: true,
        //afterGetColHeader: alignHeaders,
        //afterOnCellMouseDown: changeCheckboxCell,
        //beforeRenderer: addClassesToRows,
        outsideClickDeselects: false,
        rowHeaders: true,
        autoRowSize: true,
        manualColumnResize: true,
        renderAllRows: true,
        rowHeaderWidth: 22,
        currentRowClassName: 'currentRow',
        currentColClassName: 'currentCol',
        minSpareRows: 1,
        fixedColumnsLeft: 5,
        columnHeaderHeight: 200,
        colHeaderHeight: 120,
        manualRowMove: true,
        licenseKey: "non-commercial-and-evaluation",
        columnSummary: [
        {
            destinationRow: 0,
            destinationColumn: 9,
            reversedRowCoords: true,
            type: 'sum'
        },
        {
            destinationRow: 0,
            destinationColumn: 10,
            reversedRowCoords: true,
            type: 'sum'
        },
        {
            destinationRow: 0,
            destinationColumn: 11,
            reversedRowCoords: true,
            type: 'sum'
        }],
        
        afterChange: function (change, source) {
            if (source === 'loadData') {
                return; //don't save this change
            }
            if (change != null) {
                var ht = $("#gridBodyTableExcel").handsontable('getInstance');
                var rowNumber = change[0][0];
                var campo = change[0][1];
                var preValue = change[0][2];
                var newValue = change[0][3];
                var campoindx = 0;
                if (campo.indexOf('campo') != -1) {
                    var pro = this.getDataAtRowProp(rowNumber, 'CodProducto');
                    campoindx = campo.substr(5, 2);
                    var selectedindx = arrFields.at(campoindx - 1);
                    var codAsociado = selectedindx.codigo;
                    var suma = 0;
                    for (var i = 11; i < colCount; i++) {
                        suma += Number((this.getDataAtRowProp(rowNumber, 'campo' + Number(i - 10)) == null ? 0 : this.getDataAtRowProp(rowNumber, 'campo' + Number(i - 10))));
                    }
                    if (newValue > 0) {
                        updCant($('#<%=hdfID.ClientID%>').val(), codAsociado, pro, newValue);
                    }
                    
                    var cant = this.getDataAtRowProp(rowNumber, 'Cantidad');
                    this.setDataAtRowProp(rowNumber, 'CantidadTotal', Number(suma));
                    this.setDataAtRowProp(rowNumber, 'CantidadSobrante', Number(cant) - Number(suma));

                }
            }
        }
    });

Hi @dante.soto

Problems like this used to occur if a custom class was attached to the summary row. Can you please check if anything is being altered in this rows?

Here’s by the end of the linked section is an entry in our documentation about this situation, and how to avoid it: https://handsontable.com/docs/javascript-data-grid/column-summary/#step-4-provide-the-destination-cell-s-coordinates

Hi @dante.soto

do we have any updates regarding this issue?

Well I had to use my own javascript function and put it manually because the solution provided didn’t work. I deleted any custom class and style but still it was not working properly.

Thank you for your help.

Hi @dante.soto

Thank you for the update. I’m glad that you managed to make it work properly. I will close this topic now.