在jexcel更新表后,我没有得到新的值。

问题描述 投票:0回答:1

我无法获得新的jexcel数据.当我点击保存测试列数据不工作。我必须得到总和[ ["Honda", "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版本中,它是按照预期工作的。

javascript spreadsheet
1个回答
1
投票

你改变了单元格的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[y][x] = totals;
        }
    }
});
© www.soinside.com 2019 - 2024. All rights reserved.