HandsOnTable - 具有更新的 mergeCells 选项的 updateSettings 不起作用

HandsOnTable - updateSettings with updated mergeCells option is not working

我有一个带有 mergeCells 选项的 HandsOnTable,在特定事件中,我进行了一个服务器调用,它为我提供了更新的数据,因此合并单元格选项也需要更新。 例如在服务器调用之前,分组是每 5 行,但之后是 4 行。

我使用了 hot.updateSettings(hotOptions),其中 mergeCells 的 hotOptions 被更新,但它没有更新设置。

服务器调用前:

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);

服务器调用后:

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);

我可以销毁较早的 HOT 实例并使用新选项创建新实例(附加 fiddle 执行此操作),但我想通过 updateSettings 实现相同的效果。 更多详情:http://jsfiddle.net/ru53zo3o/1/

同时,您可以在一个对象数组中跟踪您的 "cells to merge",然后在获得新数据后修改该数组。之后你可以调用 render()。绝对是一种解决方法,但如果您需要在等待下一个版本时为任何类型的截止日期做好准备,它会帮助您渡过难关。

我想我已经解决了这个问题。

就在调用 HOT 实例的 updateSettings 之前,通过将更新后的 mergeCells 数组作为属性传递,用 Handsontable.MergeCells 对象的新实例更新其 mergeCells 属性。

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

看到它在这里工作:http://jsfiddle.net/gncb55jp/3/