ng-grid paging:总项目和页面计数错误

时间:2015-06-18 09:04:27

标签: angularjs pagination ng-grid

我已经在这里跟踪了几个与此问题相关的主题,但无法找到我的代码问题。我有一个分页的网格,但总项目数(左下角)和总页数x / n是错误的。如果我的总项目数为14,页面大小为5,则总页数为3,我看到总计数为5,总页数为1.但是,我可以使用箭头图标导航到其他页面。

这是我的代码:



   vm.gridOptions = {
            data: "vm.pagedDataList",
            rowHeight: 35,
            enableCellSelection: false,
            enableRowSelection: true,
            multiSelect: false,
            columnDefs: [
                { field: 'locationId', displayName: localize.getLocalizedString('_LocationCode_'), visible: false},
                { field: 'locationCode', displayName: localize.getLocalizedString('_LocationCode_'), width: '10%', cellTemplate: tooltipTemplateUrl },
                { field: 'locationTypeName', displayName: localize.getLocalizedString('_Locationtype_'), width: '15%', cellTemplate: tooltipTemplateUrl },
                { field: 'locationName', displayName: localize.getLocalizedString('_LocationName_'), width: '15%', cellTemplate: tooltipTemplateUrl },
                { field: 'locationDisplayName', displayName: localize.getLocalizedString('_LocationDisplayName_'), width: '15%', cellTemplate: tooltipTemplateUrl }
            ],
            enablePaging: true,
            showFooter: true,
            pagingOptions: { pageSizes: [5,10], pageSize: 5, currentPage: 1 },
            totalServerItems: 'vm.locationList.length'
        };

        $scope.$watch('vm.gridOptions.pagingOptions', function (newVal, oldVal) {
            //if (newVal !== oldVal && newVal.currentPage !== oldVal.currentPage) {
                vm.getPagedDataAsync(vm.gridOptions.pagingOptions.pageSize, vm.gridOptions.pagingOptions.currentPage, null);
            //}
        }, true);

        vm.setPagingData = function (data, page, pageSize) {
            var pagedData = data.slice((page - 1) * pageSize, page * pageSize);
            vm.pagedDataList = pagedData;
            vm.gridOptions.totalServerItems = data.length;
            if (!$scope.$$phase) {
                $scope.$apply();
            }
        };

        vm.getPagedDataAsync = function (pageSize, page) {
            vm.setPagingData(vm.locationList, page, pageSize);
        };




然后我在加载数据后在init()方法中调用它;

  vm.getPagedDataAsync(vm.gridOptions.pagingOptions.pageSize, vm.gridOptions.pagingOptions.currentPage);

1 个答案:

答案 0 :(得分:1)

更改行

   totalServerItems: 'vm.locationList.length'

   totalServerItems: 'totalServerItems',

  vm.gridOptions.totalServerItems = data.length;

    $scope.totalServerItems = data.length;