Angular ngGrid分页前进按钮不会禁用

时间:2015-07-08 13:51:08

标签: angularjs ng-grid

我有一个json,其中一些数据存储在$scope.data

JS

 $scope.pagingOptions = {
        pageSize: 5,
        currentPage: 1
    };

$scope.setPagingData = function (data, page, pageSize) {
        var pagedData = data.slice((page - 1) * pageSize, page * pageSize, page * pageSize);
        $scope.myData = pagedData;
        $scope.pagingOptions.totalServerItems = data.length;
    };

$scope.$watch('pagingOptions', function (newVal, oldVal) {
        if (newVal !== oldVal && newVal.currentPage !== oldVal.currentPage) {
            $scope.setPagingData($scope.data, $scope.pagingOptions.currentPage, $scope.pagingOptions.pageSize);
        }
    }, true);

$scope.gridOptions = {
        data: 'myData',
        enableRowSelection: false,
        enablePaging: true,
        showFooter: true,
        pagingOptions: $scope.pagingOptions
    };

HTML

<div class="gridStyle" ng-grid="gridOptions"></div>

问题

“myData”有8个结果。第一页显示5,第二页显示3,但是当数组“myData”中没有更多结果时,前向按钮不会禁用。 否则,后退按钮可以正常工作。

1 个答案:

答案 0 :(得分:0)

缺少totalServerItems: 'totalServerItems'

 $scope.gridOptions = {
            data: 'myData',
            enableRowSelection: false,
            enablePaging: true,
            totalServerItems: 'totalServerItems',
            showFooter: true,
            pagingOptions: $scope.pagingOptions
        };