I have a HoT like this:
function loadhot(parm)
{
const data = parm;
var conten = document.getElementById(‘gridBodyTableExcel’);
HoT = new Handsontable(conten, {
data,
height: 550,
width: 1400,
colWidths: [80, 170, 50, 80, 90, 170, 70, 150,80,80,80,90,180,100,50],
colHeaders: [
‘Ruc’,
‘Razon’,
‘Serie’,
‘Nro’,
‘Fecha’,
‘Glosa’,
‘OT’,
‘Clasificador’,
‘Monto Disp’,
‘MONTO’,
‘Saldo’,
‘Fec Desembolso’,
‘Beneficiario’,
‘Tipo’,
‘IGV’
],
columns: [
{ data: ‘RUC’, validator: rucValido, allowInvalid: true, type: “numeric” },
{ data: ‘RAZON’, type: “text” },
{ data: ‘SERIE’, type: “text” },
{ data: “NUMERO”, type: “text” },
{
data: ‘FECHA’,
type: “date”,
allowInvalid: false
},
{ data: ‘GLOSA’, type: “text” },
{
data: ‘OT’, validator: otValidt, allowInvalid: false, type: “numeric”
},
{
data: ‘CLASIFICADOR’,
title: ‘Clasificador’,
type: ‘dropdown’,
source: [‘2015’, ‘2016’, ‘2017’]
},
{
data: ‘MONTO_DISPONIBLE’,
type: “numeric”,
readOnly: true
},
{
data: ‘MONTO’,
type: “numeric”
},
{
data: ‘SALDO’,
type: “numeric”,
readOnly: true
},
{
data: ‘FECHA DESEMBOLSO’,
type: “date”,
allowInvalid: false
},
{
data: ‘BENEFICIARIO’,
//type: { renderer: myAutocompleteRenderer, editor: Handsontable.AutocompleteEditor },
type: ‘autocomplete’,
source: listaTmpUsuario,
strict: false,
options: {
items: 10 //options
overrides defaults
defined in bootstrap typeahead
}
},
{
data: ‘TIPO’,
title: ‘TIPO DESEMBOLSO’,
type: ‘dropdown’,
source: [‘CONTADO’, ‘CREDITO’]
},
{
data: ‘FLAG’,
title: ‘IGV?’,
type: ‘checkbox’
}
],
dropdownMenu: true,
minSpareRows: 1,
hiddenColumns: {
indicators: true
},
contextMenu: true,
multiColumnSorting: true,
filters: true,
afterGetColHeader: alignHeaders,
afterOnCellMouseDown: changeCheckboxCell,
beforeRenderer: addClassesToRows,
rowHeaders: true,
rowHeaderWidth: 22,
colHeaderHeight: 80,
manualRowMove: true,
licenseKey: "non-commercial-and-evaluation"
});
var col = HoT.countRows();
HoT.alter('insert_row', col, 20);
Then the user enters a lot of information, but he needs to remove duplicates by some columns, then summarize the amount of the repeated rows, so I get the data from HoT.LoadData() then call summarize() function , (Removing duplicates) and then send it back to HoT:
$("#btnSummarize").click(function (event) {
event.preventDefault();
var list = summarize();
loadhot(JSON.stringify(list));
});
// HoT: Constant variable for HoT object.
function summarize() {
const data = RemoveEmptyCells(HoT.getData());
const result = data.reduce((acc, curr) => {
const objInAcc = acc.find((o) => o[6] === curr[6] && o[7] === curr[7]);
if (objInAcc) objInAcc[9] += curr[9];
else acc.push( curr);
return acc;
}, []);
return result;
}
Then it throws an error:
uncaught Error: loadData only accepts array of objects or array of arrays (string given)
The format given by summarize function is something like this:
[[20492496325,“WRSOFT”,“00”,“00”,“12/07/2022”,“f”,62228,“AR36 COMBUSTIBLE - CREDITO”,100,120,null,“12/07/2022”,“289 Juan Paul Carreño Navarro”,null,null],[20492496325,“WRSOFT”,“1”,“2”,“12/07/2022”,“f”,62228,“AR38 PEAJE IDA”,20,160,null,“12/07/2022”,“289 Juan Paul Carreño Navarro”,null,null]]