Angularjs ng-repeat:在Column中添加从MySQL获取的值,对数据进行排序

时间:2017-12-05 12:51:02

标签: sorting angularjs-ng-repeat subtotal

我正在编写一段代码用于私人调整。它包含存储在MySQL数据库中的学生的详细信息。我正在用ng-repeat推迟它。我用PHP来获取数据。在代码中有两件事无法正常工作

  1. 在对列进行排序时,余额费用为“天数”和“天数”。和“剩余天数”栏目'没有得到排序。
  2. 在calcTotal(姓名)中,支付的费用总额显示为15000800012000,其中我提供的数据为15000,8000和12000
  3. 以下是代码:

    <script>
    
                        var app= angular.module("myapp",[]);
                        app.controller("mycontroller",function ($scope, $http)
                            //get data from database
                            {
                            $http.get("getData.php").then(function (response) {
                                $scope.names = response.data.records;});
                                //subtraction between dates
                                $scope.CurrentDate=new Date();
                                $scope.calDate = function(date1, date2){
                                   var dateOut1 = new Date(date1);
                                   var dateOut2 = new Date(date2);
                                   var timeDiff = Math.abs(dateOut2.getTime() - dateOut1.getTime());
    
                                   var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); 
                                   return diffDays;
                                };
                                $scope.getToday = function(){
                                    return new Date();
                                }
                                //total fees paid
                                      $scope.calcTotal = function(names){
                                            var sum = 0;
                                            for(var i = 0 ; i<names.length ; i++){
                                            sum = sum + names[i].fpaid;
                                            }
                                        return sum;
                                      };
    
                                //Sorting Column
                                $scope.sortColumn = "";
    
    
                                        $scope.sortColumn = "name";
                                        $scope.reverseSort = false;
    
                                        $scope.sortData = function (column) {
                                            $scope.reverseSort = ($scope.sortColumn == column) ?
                                                !$scope.reverseSort : false;
                                            $scope.sortColumn = column;
                                        }
    
                                        $scope.getSortClass = function (column) {
    
                                            if ($scope.sortColumn == column) {
                                                return $scope.reverseSort
                                                  ? 'arrow-down'
                                                  : 'arrow-up';
                                            }
    
                                            return '';
                                        }
                            });    
    
        </script>
        <body ng-app ="myapp" ng-controller="mycontroller">
            <table border=1>
                        <tr>
    
                            <th ng-click="sortData('name')">Name of student <div ng-class="getSortClass('name')"></div></th>
                            <th ng-click="sortData('cname')">Course Name <div ng-class="getSortClass('cname')"></div> </th>
                            <th ng-click="sortData('cfees')">Course fees  <div ng-class="getSortClass('cfees')"></th>
                            <th ng-click="sortData('fpaid')">Fees paid  <div ng-class="getSortClass('fpaid')"></th>
                            <th ng-click="sortData('bfees')">Balance Fees<div ng-class="getSortClass('bfees')"></th>   //sorting is not working on this column
                            <th ng-click="sortData('sdate')">Start Date of Course <div ng-class="getSortClass('sdate')" ></th>
                            <th ng-click="sortData('edate')">End date of course <div ng-class="getSortClass('edate')" ></th>
                            <th> No of days </th>
                            <th>No of Days remaining </th>
    
                        </tr>
                            <tr   ng-repeat="x in names  | filter: searchText | orderBy:sortColumn">
    
                                <td>{{x.Bank}}</td>
                                <td>{{x.cname}}</td>
                                <td >{{x.cfees}}</td>
                                <td>{{x.fpaid }}</td>
                                <td ng-model="bfess">{{x.cfees-x.fpaid}}</td>
                                <td>{{x.sdate | date:'dd-MM-yyyy'}}</td>
                                <td>{{x.edate | date:'dd-MM-yyyy'}}</td>
                                <td>{{calDate(x.edate,x.sdate)}}</td>
                                <td>{{calDate(x.edate,getToday()| date:'dd-MM-yyyy')}}</td>                     
                        </tr>
                        <tr>
                            <td>Total fess paid by students: {{ calcTotal(names) }}</td>
                        </tr>
    
                    </table>
    

0 个答案:

没有答案