Formulas not working in nghandsontable

2019-09-05 07:44发布

问题:

my code is look like this,still i am not able to calculate the sum value. Can any one help me to solve this.I want to add the values of a and b in C column. But I'm getting output as 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>

回答1:

You can't directly refer a value to another value inside an object. It is possible, but you need to invoke a function which you declare as a value of 'c'.

A more simple aproach will be adding 'c' outside the tabledata declaration:

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