ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

Paging controller does not show currentPage in the input control (was working in 2.0.6)

Open naory opened this issue 13 years ago • 9 comments

I am using AngularJS 1.2-rc-3 I have the a controller that is accessing s SpringData REST repository. it accepts url parameters of limit (= pageSize) and page (= currentPage) I have tested this with version 2.0.6 and it works but using 2.0.7 the paging controller works but the input is blank. typing a (valid) page number seems to remove the currentPage from the $scope.pagingOptions which I am debuging on the page:

before typing (input control is blank):

DEBUG: { "pageSizes": [ 3, 5, 10, 25, 50 ], "pageSize": 3, "currentPage": 1 }

after typing '1' into the input:

DEBUG: { "pageSizes": [ 3, 5, 10, 25, 50 ], "pageSize": 3 }) 

my controller code:

angular.module('myApp.controllers', []).
  controller('UsersCtrl', ['$scope', '$http', function($scope, $http) {

        $scope.filterOptions = {
            filterText: "",
            useExternalFilter: true
        };
        $scope.totalServerItems = 0;
        $scope.pagingOptions = {
            pageSizes: [3, 5, 10, 25, 50],
            pageSize: 3,
            currentPage: 1
        };


        $scope.setPagingData = function(data, page, pageSize){
//            var pagedData = data.slice((page - 1) * pageSize, page * pageSize);
            $scope.myData = data.content;
            $scope.totalServerItems = data.page.totalElements;
            if (!$scope.$$phase) {
                $scope.$apply();
            }
        };



        $scope.getPagedDataAsync = function (pageSize, page, searchText) {
            setTimeout(function () {
                var data;
                if (searchText) {
                    var ft = searchText.toLowerCase();
                    $http.get('/api/users', {'limit': pageSize, 'page': page})
                    $http({method: 'GET', url: '/api/users', params: {'limit': $scope.pagingOptions.pageSize, 'page': $scope.pagingOptions.currentPage}})
                        .success(function (largeLoad) {
                        data = largeLoad.filter(function(item) {
                            return JSON.stringify(item).toLowerCase().indexOf(ft) != -1;
                        });
                        $scope.setPagingData(data,page,pageSize);
                    });
                } else {
                    //$http.get('/api/users', {'limit': pageSize, 'page': page})
                    $http({method: 'GET', url: '/api/users', params: {'limit': $scope.pagingOptions.pageSize, 'page': $scope.pagingOptions.currentPage}})
                        .success(function (largeLoad) {
                        $scope.setPagingData(largeLoad,page,pageSize);
                    });
                }
            }, 100);
        };

        $scope.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOptions.currentPage);

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

        $scope.$watch('pagingOptions.pageSize', function (newVal, oldVal) {
            if (newVal !== oldVal) {
                $scope.pagingOptions.currentPage = 1;// if pageSize changes - start from first page
                $scope.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOptions.currentPage, $scope.filterOptions.filterText);
            }
        }, true);

        $scope.$watch('filterOptions', function (newVal, oldVal) {
            if (newVal !== oldVal) {
                $scope.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOptions.currentPage, $scope.filterOptions.filterText);
            }
        }, true);


        $scope.myColumnDefs = [{ field: 'firstName', displayName: 'First Name'},
            { field: 'lastName', displayName: 'Last Name' }];


        $scope.gridOptions = {
            data: 'myData',
            columnDefs: $scope.myColumnDefs,
            multiSelect: false,
            selectedItems: [],
            enableSorting: false, // filter and sort should be on the entire data set (server side)
            enableHighlighting: true, // enable copy of text from grid cells
            enablePaging: true,
            showFooter: true,
            totalServerItems: 'totalServerItems',
            pagingOptions: $scope.pagingOptions,
            filterOptions: $scope.filterOptions
        };



  }])
  .controller('RolesCtrl', ['$scope', function($scope) {
       //...
  }]);

naory avatar Nov 03 '13 19:11 naory

I experience the same issue. It has something to do with the angular version.

See official plunker from ng-grid docs: http://plnkr.co/edit/50vJrs?p=preview

Then change angular version it uses to: https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js

It doesn't load records (I used $timeout instead of setTimeout to fix it locally) and doesn't display currentPage.

restless avatar Nov 07 '13 10:11 restless

With angular 1.2.5 and ng-grid 2.0.7, at the initialisation, the currentPage is not shown, but the pager works fine, and if you use it to change page, the currentPage is now shown

apesme avatar Dec 18 '13 08:12 apesme

Fixed in 2.0.8 http://plnkr.co/edit/qD65q1?p=preview

roblarsen avatar Dec 21 '13 15:12 roblarsen

Plunkr link is broken. Also, when will 2.0.8 be available?

rconrad avatar Jan 28 '14 20:01 rconrad

Soon, I think.

roblarsen avatar Jan 28 '14 20:01 roblarsen

As in [hours, days, weeks, months]?

rconrad avatar Jan 28 '14 21:01 rconrad

As in, I can't really answer right now. We've got three people active on the project. Two of them are working almost exclusively on 3.0. I'm trying to shepherd a couple of decent 2.* branch releases out the door, but I'm currently swamped and haven't been able to do much. So... I can't give you a definitive answer. If my time opens up over the next week, then a week. If I'm busy until March, then... March. As soon as I possibly can, is as good as I can share.

roblarsen avatar Jan 28 '14 21:01 roblarsen

Thanks

rconrad avatar Jan 29 '14 13:01 rconrad

I use angular 1.2.13, the dataTable works well but I also have the "current page" input field empty. waiting for the 2.0.8... hopefully it will be there soon.

jaybe78 avatar Mar 26 '14 01:03 jaybe78