【问题标题】:Formulas not working in nghandsontable公式在 nghandsontable 中不起作用
【发布时间】:2015-11-15 04:34:22
【问题描述】:

我的代码看起来像这样,但我仍然无法计算总和值。谁能帮我解决这个问题。我想在 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>

【问题讨论】:

    标签: angularjs handsontable


    【解决方案1】:

    您不能直接将一个值引用到对象内的另一个值。这是可能的,但您需要调用一个您声明为 'c' 值的函数。

    更简单的方法是在 tabledata 声明之外添加“c”:

      for (var i = 0; i < tabledata.length; i++) {
        $scope.tabledata[i].c = $scope.tabledata[i].a + $scope.tabledata[i].b;
      }
    

    【讨论】:

      猜你喜欢
      • 2016-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多