我的代码看起来像这样,仍然无法计算总和值。任何人都可以帮我解决这个问题。我想在C列中添加a和b的值。但我得到输出为SUM(A1:B1)。
Can anyone tel me how to solve this?The same code works fine in when done using Jquery.
<script src="handsontable.full.js" type="text/javascript"></script>
<link href="handsontable.full.css" rel="stylesheet" type="text/css">
<script src="angular.js" type="text/javascript"></script>
<script src="ngHandsontable.js" type="text/javascript"></script>
<script>
var app = angular.module('myApp', ['ngHandsontable']);
app.controller('myCtrl', function($scope) {
$scope.tabledata=[ {a:'73903', b:'15015', c:'=SUM(A1:B1)'},
{a:'73904', b:'15013', c:'=SUM(A2:B2)'},
{a:'73905', b:'15014', c:'=SUM(A3:B3)'}
];
$scope.gridOptions = {
data: 'tabledata'
};
$timeout(function(){
tableInstance.updateSettings({formulas: true});
tableInstance.render();
},10);
});
</script>
**THE HTML CODE**
<div style="position: relative;" data-ng-controller="myCtrl">
<hot-table
hotInstance="tableInstance"
formulas="true"
colHeader="true"
rowHeaders="false"
contextMenu="false"
datarows="tabledata"
colWidths="[100,100,100]">
<hot-column data="a" title="'A'" ></hot-column>
<hot-column data="b" title="'B'"></hot-column>
<hot-column data="c" title="'Total'"></hot-column>
</hot-table>
</div>
答案 0 :(得分:0)
您无法直接将值引用到对象内的其他值。这是可能的,但是你需要调用一个你声明为&#39; c&#39;的值的函数。
更简单的方法是添加&#39; c&#39;在tabledata声明之外:
for (var i = 0; i < tabledata.length; i++) {
$scope.tabledata[i].c = $scope.tabledata[i].a + $scope.tabledata[i].b;
}