Set page number while table is rendering
See original GitHub issueHi.
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;
Issue Analytics
- State:
- Created 9 years ago
- Comments:7
Top GitHub Comments
@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…