2015-10-14 98 views
1

我嘗試即時更新HandsonTable設置。設置似乎更新​​,但呈現的表仍然使用以前的設置。更新現有HandsOnTable實例的設置

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

updateSettings文檔: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>

回答

0

是啊,所以你要擺脫的第二個參數到您的updateSettings。不知道它做了什麼,但如果你在你的小提琴中擺脫它,它會正確更新。只是fyi,不需要重新渲染,因爲無論如何它最終都會這樣做。