Set page number while table is rendering
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;
+1 same problem, on a newer version and this doesn't solve the problem for me.
$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
$scope.tableParams.page(1)
Working Thanks.
@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 I had the same issue.
I added $scope.tableParams.reload(); right after $scope.tableParams.page(1); and it worked.
+1 @konsouv Thanks for your Answer, it is working for me too..