我的ng-table显示了它应该只显示10的所有值

时间:2014-12-04 19:25:54

标签: angularjs pagination ngtable

我有一个计算函数,当被调用时,它取几个值并用它们用结果填充ng表。一切正常,但表格应该分页,一次只显示10个值。相反,所有值都会立即显示。在页面底部显示下一个和后退按钮,用于移动表格的值。下面是我正在使用的angularjs代码。我不确定问题出在哪里。

$scope.tableParams = new ngTableParams({
        page: 1,        //show first page
        count: 10       //conunt per page
    },{
        total: $scope.subsidyPaymentScheduleTable.length,
            getData: function($defer, params){
                $defer.resolve($scope.subsidyPaymentScheduleTable.slice((params.page() - 1) * params.count(), params.page() * params.count()));
            }

    });

    //populates the Subsidy table
    $scope.populateSubsidyTable = function(monthlySubsidyRedAm, startingSubsidy, monthsOnSubsidy)
    {
        var currentSubsidy = 0;
        var currentDate = $scope.startingDate;
        var subsidyDate = new Date();
        var monthsLeft = monthsOnSubsidy
        $scope.subsidyPaymentScheduleTable = [];
        var subsidyPaymentScheduleArray = [];

        if(startingSubsidy > 1)
        {
            currentSubsidy = startingSubsidy;
        }

        if(monthlySubsidyRedAm <=0)
        {
            totalAmount = currentSubsidy * 6;
        }
        else
        {
            //the first month

            $scope.subsidyPaymentScheduleTable.push({
                    subsidyDate: currentDate,
                    subsidyAmount: currentSubsidy
            });

            $scope.totalSubsidy = $scope.totalSubsidy + currentSubsidy;

            //the first 5 months after the first
            for(i=2; i <= 6; i++)
            {
                currentDate = moment(currentDate).add(1,'months').format("MM/DD/YYYY");


                $scope.subsidyPaymentScheduleTable.push({
                    subsidyDate: currentDate,
                    subsidyAmount: currentSubsidy
                });

                monthsLeft = monthsOnSubsidy - 6;

                $scope.totalSubsidy = $scope.totalSubsidy + currentSubsidy;

            }
            //the rest of the subsidies
            while(monthsOnSubsidy > 0)
            {
                if((currentSubsidy - monthlySubsidyRedAm) > 1)
                {
                        currentSubsidy = currentSubsidy - monthlySubsidyRedAm;

                        currentDate = moment(currentDate).add(1,'months').format("MM/DD/YYYY");

                        $scope.subsidyPaymentScheduleTable.push({
                            subsidyDate: currentDate,
                            subsidyAmount: currentSubsidy
                        });

                        $scope.totalSubsidy = $scope.totalSubsidy + currentSubsidy;

                        monthsLeft--;
                }
                else
                {
                    break;
                }
            }

            //reload subsidy table
            $scope.tableParams.total($scope.subsidyPaymentScheduleTable.length);
            $scope.tableParams.reload();
        }
    }

这是html代码

<table ng-table="tableParams" class="table subsidyPaymentScheduleTable">
        <tr data-ng-repeat="subsidy in subsidyPaymentScheduleTable" class="clickableRow">
            <td data-title="'Date'">
                {{subsidy.subsidyDate}}
            </td>
            <td data-title="'Amount'">
                {{subsidy.subsidyAmount | currency:"$"}}
            </td>
        </tr>
    </table>

1 个答案:

答案 0 :(得分:0)

我发现当我在$scope下声明变量而不是var data = [];时,ng-table似乎没有正确地看到它们。