Formulas not working in nghandsontable

早过忘川 提交于 2019-12-13 08:50:55

问题


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;
  }


来源:https://stackoverflow.com/questions/32136795/formulas-not-working-in-nghandsontable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!