2

I have followed several threads in here related to the issue but couldn't find the issue with my code. I have a paged ng-grid, but the total item count (bottom left corner) and the total page count x/n is wrong. When I should have 14 as total items and 3 as total pages for a page size of 5, I see the total count as 5 and the total pages as 1. However, I can navigate to the other pages with the arrow icon.

Here is my code:

 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); };

Then I call this in the init() method, after the data is loaded;

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

1 Answer 1

1

change line

 totalServerItems: 'vm.locationList.length' 

to

 totalServerItems: 'totalServerItems', 

and

 vm.gridOptions.totalServerItems = data.length; 

to

 $scope.totalServerItems = data.length; 
Sign up to request clarification or add additional context in comments.

1 Comment

This method is not updating the number of records for the first time before pagination is triggered. When pagination is triggered then the value becomes correct.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.