我有handontable:var dataObject = [ ['', '', '', '', '', '', 2017, 2017, 2017], ['Item ID', 'Item Name', '', 'Split', 'Weighed LRA', 'LRA', 3, 2, 1], ['556874', 'POMEGRANATE PEONY BB 1L', '', '=ROUND(CONCEPT_SUM*E3;0)', '=F3/SUM(F3:F5)', "=IF(SUM(G3:I3)=0,0,AVERAGEIF(G3:I3, '<>0'))", 0.13, 0.45, 0.26], ['569066', 'POMEGRANATE PEONY BB 1L', '', '=ROUND(CONCEPT_SUM*E4;0)', '=F4/SUM(F3:F5)', "=IF(SUM(G4:I4)=0,0,AVERAGEIF(G4:I4, '<>0'))", 0, 0, 0], ['569076', 'POMEGRANATE PEONY BB 1L', '', '=ROUND(CONCEPT_SUM*E5;0)', '=F5/SUM(F3:F5)', "=IF(SUM(G5:I5)=0,0,AVERAGEIF(G5:I5, '<>0'))", 0.13, 0, 0]]var hotElement = document.querySelector('#hot')var hotSettings = { data: dataObject, licenseKey: 'non-commercial-and-evaluation', colWidths: [80, 200, 17, 100, 90, 90, 50, 50, 50], contextMenu: false, rowHeaders: true, colHeaders: true, formulas: { variables: { CONCEPT_SUM: 400, } }};var hot = new Handsontable(hotElement, hotSettings)$('#split-sum').change(function(event) { hot.updateSettings({ formulas: { variables: { CONCEPT_SUM: parseInt($('#split-sum').val()) } } });});<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/npm/handsontable/dist/handsontable.full.min.js"></script><link href="https://cdn.jsdelivr.net/npm/handsontable/dist/handsontable.full.min.css" rel="stylesheet" media="screen"><input id="split-sum" name="split-sum" title="Concept/Offer Sum" type="text" value="" placeholder="Concept/Offer Sum"><div id="app"> <div id="hot"> </div></div>我想在输入框更改后更新公式变量。下面的代码行似乎什么都不做hot.updateSettings({formulas: { variables: { CONCEPT_SUM: parseInt($('#split-sum').val()) } }});
1 回答
扬帆大鱼
TA贡献1799条经验 获得超9个赞
而不是使用updateSettings我会使用公式插件中的函数。
您可以尝试以下方法:
$('#split-sum').change(function(event) {
var formulaPlugin = hot.getPlugin('formulas');
formulaPlugin.setVariable('CONCEPT_SUM', parseInt($('#split-sum').val()));
formulaPlugin.recalculateFull();
});
首先,您设置CONCEPT_SUM变量,setVariable然后再次强制单元格计算。
添加回答
举报
0/150
提交
取消