Merge Cells get Null Data

Tags: #<Tag:0x00007efc647e7c48> #<Tag:0x00007efc647e7a40>

Hello,

I’m new to handsontable, currently i use Version: 14.4.0
I have a problem when using merge cell…when I get data with

console.log(hot.getData());
console.log(hot.getSourceData());

It keeps giving me a null value on the merged cells is it proper behavior?
how do you get the merged data instead of the null value?

Let’say the setup is
mergeCells:[{ row: 0, col: 0, rowspan: 1, colspan: 3 }]

The result is :
[“Data Merge”,null,null,“Data”,“Data”];

How to make it :
[“Data Merge”,“Data Merge”,“Data Merge”,“Data”,“Data”];

am I missing some setting?

Hi @simpleminimalis

When we merge cells on the initialization, this is what we get

Table
04

Outcomes (the getData and getSourceData calls)

Demo: https://stackblitz.com/edit/kchucf-wurhvs?file=index.js

And the same goes if we use the demo to merge cells by hand (manually via context menu)

Table
27

Outcomes (the getData and getSourceData calls)

Demo: https://stackblitz.com/edit/kchucf-hnquzi?file=index.js

The mergeCells plugin removed data from elements that take part in merging - it does not copy the data.

If, you’d like to have the data copied you can use the afterMergeCells hook to call setDataAtCell() method on those cells.

Hi @aleksandra_budnik

Thank you for your explanation, I’ll try it…

Btw, this is a merge example


and when I check the generated table it has the value

However, based on your explanation…the current behavior is it will get null when you get the data

I hope in the future/next update it will provide a built-in setting to “include” this merged data like…

mergeCells: [ { enable: true, includeValue: true } ]

Edit 1:
I have tried the afterMergeCells hook…however, it’s only called on when we merge from the ContextMenu

How to call/trigger it when the merge is called on the initial load or at updateSetting to bind the setDataAtCell() method?

In the DOM, we have different results as the mergeCells plugin creates a layer of cells on top of the actual grid.

And here’s the code example for the hook being called after the actual merge and work for init merges and those from the context menu https://stackblitz.com/edit/kchucf-jkmops?file=index.js.