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);
change line
to
and
to