【问题标题】:My ng-table is displaying all it's values when it should only be displaying 10我的 ng-table 显示它的所有值,而它应该只显示 10
【发布时间】:2015-02-02 19:44:46
【问题描述】:

我有一个计算函数,当调用它时,它会获取几个值并使用它们来填充一个 ng-table 的结果。一切正常,除了表应该分页一次只显示 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>

【问题讨论】:

    标签: angularjs pagination ngtable


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2021-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-20
      • 2013-09-12
      • 2019-05-16
      相关资源
      最近更新 更多