更新现有HandsOnTable实例的设置

Update settings of an existing HandsOnTable instance

本文关键字:设置 实例 HandsOnTable 更新      更新时间:2023-09-26

我尝试动态更新HandsonTable设置。设置似乎更新了,但呈现的表仍然使用以前的设置。

的例子:http://jsfiddle.net/kAFWA/30/

updatessettings文档:http://docs.handsontable.com/0.18.0/Core.html#updateSettings

var ht;
$(document).ready(function() {
  $("#example1").handsontable({
    minRows: 5,
    minCols: 5,
    colHeaders: ["Header 1", "Header 2", "Header 3"],
    rowHeaders: true,
    contextMenu: {
      items: {
        "edit_Header": {
          name: "Edit this Header!!"
        }
      }
    }
  });
  ht = $('#example1').handsontable("getInstance");
});
function updateContextMenu() {
  console.log(ht);
  ht.updateSettings({
    minRows: 4,
    minCols: 4,
    colHeaders: ["Header 4", "Header 5", "Header 6"],
    contextMenu: {
      items: {
        "edit_Header": {
          name: "Another Text"
        },
      }
    }
  }, true);
  console.log('here');
  ht.render();
}
<link href="http://handsontable.com/dist/jquery.handsontable.full.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://handsontable.com/dist/jquery.handsontable.full.js"></script>
<div id="example1" class="handsontable"></div>
<p>
  <button type="button" name="update" title="Update context menu" onclick="updateContextMenu()">Update context menu</button>
</p>

是的,所以您想要去掉updateSettings的第二个参数。不知道它是做什么的,但如果你把它从你的小提琴中删除,它会正确更新。仅供参考,不需要重新渲染,因为它在最后无论如何都会这样做。