4

I have a HandsOnTable with mergeCells option, on particular event I make a server call which gives me updated data and hence merge cells options also need to be updated. For e.g. before server call, grouping was for every 5 rows, but after it's for 4 rows.

I used hot.updateSettings(hotOptions) in which mergeCells of hotOptions is updated, but it does not update the setting.

Before server call:

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 server call:

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 earlier HOT instance and create new one with new options (attached fiddle does this), but I want to achieve the same with updateSettings. More details: http://jsfiddle.net/ru53zo3o/1/

YakovL
  • 7,557
  • 12
  • 62
  • 102
Sohan Soni
  • 1,207
  • 21
  • 35
  • 1
    Looks like its a known issue with HandsOnTable and they will be fixing it in upcoming release i.e. 0.15.1. We can track the chagnes at : https://github.com/handsontable/handsontable/issues/1788 – Sohan Soni Jun 24 '15 at 07:55

2 Answers2

2

I think I have fixed this.

Just before calling updateSettings of the HOT instance, update its mergeCells attribute with the new instance of Handsontable.MergeCells object by passing updated mergeCells array as an attribute.

hotOptions.mergeCells = [{row: 0, col: 0, rowspan: 2, colspan: 3} ];
hot.mergeCells = new Handsontable.MergeCells(hotOptions.mergeCells);
hot.updateSettings(hotOptions);

See it working here: http://jsfiddle.net/gncb55jp/3/

YakovL
  • 7,557
  • 12
  • 62
  • 102
Sohan Soni
  • 1,207
  • 21
  • 35
1

In the meantime you could keep track of your "cells to merge" in an object array, then modify that array once you get the new data. Afterwards you can call render(). Definitely a workaround, but it will tide you over if you need to have it ready for a deadline of any kind while your waiting for the next release.

brinegjr
  • 86
  • 6
  • I tried render after updateSettings call, but it does not update the display i.e. it shows data with previous merge cell settings – Sohan Soni Jul 17 '15 at 09:27