question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set page number while table is rendering

See original GitHub issue

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;

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
konsouvcommented, Jul 12, 2017

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

0reactions
hardikBharadavacommented, Aug 8, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to deal with page breaks when printing a large HTML table
The only plausible solution I can think of is using stacked DIVs instead of a table and force page-breaks if needed.. but before...
Read more >
Display page numbers or other paginated report properties
To add total number of pages after the page number · Right click the text box with the expression and click Expressions. ·...
Read more >
Tables in HTML documents
Render the cells, row by row and grouped in appropriate columns, ... When set for the TABLE element, the dir attribute also affects...
Read more >
HTML table basics - Learn web development | MDN
A table is a structured set of data made up of rows and columns (tabular data). A table allows you to quickly and...
Read more >
page.info() - DataTables
The paging state of the table can often be useful to understand what data is ... number of records in the table (both...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found