ng-table icon indicating copy to clipboard operation
ng-table copied to clipboard

Set page number while table is rendering

Open ErickGallani opened this issue 12 years ago • 7 comments

Hi.

I have two pages, with 1 table each.

The first page has a link on each row to send the user to the second page. In the second page I have a "Back" button to send user back to the previous page.

The problem here is that I need to keep que state of the page like filters, sorting, the page number (in the table) his choose, number of lines per page, etc etc.

I'm using angular js with ng-table, so was easy to use the local storage to save this informations and setting everything back when the user go back to the page. The only thing that doesn't work is setting the page number. No matter what page I set by using "$scope.tableParams.page(pageNumber);" I only get in the first page in the first rendering of the table.

Looking at the source code of ng-table, I was able to "correct that" by changing the params watch.

Now I'm wondering if it will cause any trouble.

It was

$scope.$watch('params.$params', function (newParams, oldParams) {
        $scope.params.settings().$scope = $scope;

        if (!angular.equals(newParams.filter, oldParams.filter)) {
            delayFilter(function () {
                $scope.params.$params.page =1
                $scope.params.reload();
            }, $scope.params.settings().filterDelay);
        } else {
            $scope.params.reload();
        }
    }, true);

I changed the following line

$scope.params.$params.page =1 

to this

$scope.params.$params.page = ($scope.params.$params.page != undefined) ? $scope.params.$params.page : 1;

ErickGallani avatar Nov 13 '14 16:11 ErickGallani

+1 same problem, on a newer version and this doesn't solve the problem for me.

noahmatisoff avatar Nov 09 '15 21:11 noahmatisoff

$scope.tableParams.$params.page =1 isn't working in latest updates of ng-table. TypeError: Cannot set property 'page' of undefined

How we can fix it

aqibmumtaz avatar Nov 13 '15 07:11 aqibmumtaz

$scope.tableParams.page(1)

christianacca avatar Nov 13 '15 07:11 christianacca

Working Thanks.

aqibmumtaz avatar Nov 13 '15 12:11 aqibmumtaz

@christianacca, @ErickGallani $scope.tableParams.page(1) changing to First page Programetically. but after it, sorting functionality is not working, what am I doing is, having multiple pages, if one is sorting column and is not on First page, redirecting it to first page. Above provided same code implemented, but it is not working for me. Any Other Solution? Thanks for Your Help.!!

hardikBharadava avatar Dec 14 '16 11:12 hardikBharadava

@hardikBharadava I had the same issue. I added $scope.tableParams.reload(); right after $scope.tableParams.page(1); and it worked.

konsouv avatar Jul 12 '17 06:07 konsouv

+1 @konsouv Thanks for your Answer, it is working for me too..

hardikBharadava avatar Aug 08 '17 06:08 hardikBharadava