HandsOnTable - updateSettings with updated mergeCells option not working
I have a HandsOnTable option with a parameter mergeCells
, on a specific event I make a call to the server that gives me the updated data, and hence the cell merge options also need to be updated. Ex. before the server call, the grouping was for every 5 rows, but after that for 4 rows.
I used hot.updateSettings(hotOptions)
one that updates mergeCells
hotOptions, but it doesn't update settings.
Before calling the server:
var hotOptions =
{
data: Handsontable.helper.createSpreadsheetData(5,5),
colWidths: [47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47],
rowHeaders: true,
colHeaders: true,
contextMenu: true,
mergeCells: [
{row: 0, col: 0, rowspan: 2, colspan: 2},
{row: 3, col: 3, rowspan: 2, colspan: 2}
]
};
hot = new Handsontable(container, hotOptions);
After calling the server:
hotOptions.mergeCells = [
{row: 0, col: 0, rowspan: 3, colspan: 3},
{row: 0, col: 3, rowspan: 2, colspan: 1}
];
//just to prove that data is updating
hotOptions.colWidths = [100, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47];
hot.updateSettings(hotOptions);
I can destroy the previous HOT instance and create a new one with new parameters (the attached script does this), but I want to achieve the same with updateSettings
. More details: http://jsfiddle.net/ru53zo3o/1/
source to share
I think I fixed this.
Before calling the updateSettings
HOT instance, update its attribute with a mergeCells
new object instance Handsontable.MergeCells
, passing the updated array mergeCells
as an attribute.
hotOptions.mergeCells = [{row: 0, col: 0, rowspan: 2, colspan: 3} ];
hot.mergeCells = new Handsontable.MergeCells(hotOptions.mergeCells);
hot.updateSettings(hotOptions);
See how it works here: http://jsfiddle.net/gncb55jp/3/
source to share
In the meantime, you can keep track of your "merge cells" in an array of objects, and then modify that array when new data is received. You can call render () afterwards. Definitely a workaround, but it will knock you off if you need it ready by the deadline while you wait for the next release.
source to share