可手动保存的公式值 [英] Handsontable Save formula values
问题描述
我想将handontable集成到我的网站,但是遇到一个问题,当我试图保存RuleJS创建的数据(公式支持)时,脚本给了我一个像(= $ A1 * $ B1).我试图得到简单的数学结果乘以价格和货币.如何保存表值,而不是从表中保存?
I want integrate handsontable to my site, but a got a problem, when im trying to save data created by RuleJS (formula support), script give me a formula back like (=$A1*$B1). Im trying to get result of simple math multiply price and currency. How to save table values, not from sourse?
workig代码在jsfiddle上: http://jsfiddle.net/zetwin/qhjuuk5j/4/
The workig code is on jsfiddle: http://jsfiddle.net/zetwin/qhjuuk5j/4/
document.addEventListener("DOMContentLoaded", function() {
var people = [
{base_price :'99', price:'13', unit:'=A1*B1'},
{base_price :'89.99', price:'13.43', unit:'=A2*B2'}
],
example1 = document.getElementById('example1'),
settings1;
settings1 = {
data: people,
formulas: true,
rowHeaders: true,
colHeaders: true,
colHeaders: [
'Price', 'Currency', 'USD'],
columns: [
{data: 'base_price'},
{data: 'price'},
{data: 'unit'}
]
};
var hot = new Handsontable(example1, settings1);
$('.push').click(function () {
data = hot.getData();
console.log(data);
//$('.result').text(data);
});
});
谢谢!
推荐答案
对象是属性Handsontable plugin.matrix.data-单元格列表,根据列表中的公式计算得出.每个单元格都有一个属性值-这是显示的结果.要获取所有数据,必须使用以下函数:Handsontable.plugin.helper.cellValue或Handsontable.plugin.helper.cellRangeValue.
An object is a property Handsontable plugin.matrix.data - a list of cells, which are calculated according to the formulas in the table. Each cell has a property value - this is the displayed result. To get all of the data will have to use the function: Handsontable.plugin.helper.cellValue or Handsontable.plugin.helper.cellRangeValue.
例如您的jsfiddle:
For example for your jsfiddle:
从单元格的右上角获取:
to get from the top-right of the cell:
data = hot.plugin.helper.cellValue ('C1');
console.log (data);
48168.89000000001获取所有单元格(列表)的值:
48168.89000000001 obtaining values of all cells (a list):
data = hot.plugin.helper.cellRangeValue ('A1', 'C2');
console.log (data);
Array [6]:0:625.57 1:656.95 2:77 3:3 4:48168.89000000001 5: 50585.15长度:6
Array [6]: 0: 625.57 1: 656.95 2: 77 3: 77 4: 48168.89000000001 5: 50585.15 length: 6
我认为这是比cellRangeValue更好的方法.但是在此基础上,我们可以编写更舒适的内容.看. Handsontable.plugin.helper.cellRangeValue
I think that is a better method than cellRangeValue not. But on this basis we can write something more comfortable. See. Handsontable.plugin.helper.cellRangeValue
这篇关于可手动保存的公式值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!