gpt4 book ai didi

javascript - jexcel 更新表后我没有得到新值

转载 作者:行者123 更新时间:2023-12-02 21:00:47 26 4
gpt4 key购买 nike

我无法获取新的 jexcel 数据。当我单击保存测试列数据时不起作用。我必须得到总和[ [ “本田”, “2”, “2”, ”” ]]
这是我的代码

    var datagrid = jexcel(document.getElementById('my-spreadsheet'), {
columns: [
{title: 'Model', width: 300},
{title: 'Price', type: 'numeric', width: 80},
{title: 'Tax', type: 'numeric', width: 100},
{title: 'Test', type: 'numeric', width: 100}
],
data: [
['Honda']
],
updateTable: function (instance, cell, col, row, val, label, cellName) {
if (col == 1) {
Price = val;
}
if (col == 2) {
Tax = val;
}
if (col == 3) {
totals = Number(Price) + Number(Tax);
$(cell).text(totals);
}
}
});
function save() {
var data = datagrid.getJson();
console.log(data, 'data');
}

我知道有一个像 =B1+C1 这样的公式...但我已手动输入网格中的所有行。

实际上它在 jexcel 1.5 版本中按预期工作

最佳答案

您正在更改单元格中的innerHTML,而不更改数据源对象。您可以使用以下代码修复该问题:

   var datagrid = jexcel(document.getElementById('my-spreadsheet'), {
columns: [
{title: 'Model', width: 300},
{title: 'Price', type: 'numeric', width: 80},
{title: 'Tax', type: 'numeric', width: 100},
{title: 'Test', type: 'numeric', width: 100}
],
data: [
['Honda']
],
updateTable: function (instance, cell, col, row, val, label, cellName) {
if (col == 1) {
Price = val;
}
if (col == 2) {
Tax = val;
}
if (col == 3) {
totals = Number(Price) + Number(Tax);
// Update labels
$(cell).text(totals);
// Update data source
instance.jexcel.options.data[row][col] = totals;
}
}
});

关于javascript - jexcel 更新表后我没有得到新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61360625/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com