handsontable / handsontable

JavaScript data grid with a spreadsheet look & feel. Works with React, Angular, and Vue. Supported by the Handsontable team ⚡
https://handsontable.com
Other
19.15k stars 2.94k forks source link

[Bug]: Object array data source causes spliceRow call error: rowData.slice is not a function #10943

Closed watchingfun closed 2 weeks ago

watchingfun commented 3 weeks ago

Describe the bug

When using a two-dimensional array, spliceRow is called normally, but when using an object array, an error is reported.

Is it true that spliceRow cannot be used when using object arrays? I see no explanation in the documentation.

Video/Screenshots

image

Provide a link to the demo with the bug reproduction

https://jsfiddle.net/qkhrdbo1/

Handsontable version

handsontable@14.3

Framework version

No response

Your environment

chrome

AMBudnik commented 2 weeks ago

Hi @watchingfun

The spliceRow(), as mentioned in the documentation at https://handsontable.com/docs/react-data-grid/api/core/#splicerow, is made for arrays (not objects).

Zrzut ekranu 2024-04-24 o 09 27 26

Underneath it calls thepopulateFromArray method https://github.com/handsontable/handsontable/blob/56d54d6e98da2b4d376829cb4077f4dea7b4a131/handsontable/src/dataMap/dataMap.js#L690C14-L690C31

so to add columns with data you'd need to alter the data object or change the columns settings and then add data, for example with the setDataAtCell() or setDataAtRowProp.

watchingfun commented 2 weeks ago

Thank you for your answer. The problem was caused by my misunderstanding of the documentation, so I could add new rows via hot.alter('insert_row', hot.countRows()); and then set the row data via setDataAtRowProp