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:
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));
}
}
}
});