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.

Scroll up on pageChange event.

See original GitHub issue

Angular version: ^6.0.0

ngx-pagination version: ^3.1.1

Description of issue: On each page change i want to scroll up to top of my component page, how can i access the pageChange event or maybe i can do this another way? I have noticed that in your examples your page doesn’t change any kind of position via CSS either, so i am wondering if it is possible at all or not.

Steps to reproduce: Basic example from demos

Expected result: I need to scroll up to top of component html page when page changes. Actual result: Page stays at same position when page changes.

Demo: (if possible, edit this StackBlitz demo and paste the link to your fork)

Any relevant code:


Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

12reactions
michaelbromleycommented, Jul 24, 2018

I mean something like this:

<pagination-controls (pageChange)="onPageChange($event)"></pagination-controls>
onPageChange(page: number) {
   this.currentPage = page;
   window.scrollTo(0, 0);
}
1reaction
snblackoutcommented, Aug 13, 2021

In Angular Ionic, do the following:

Import Content view:

@ViewChild(Content) content: Content;

Create a function to scroll to an element ID:

scrollTo(element: string) {
    let elem = document.getElementById(element);
    if (elem) {
      var box = elem.getBoundingClientRect();

      var body = document.body;
      var docEl = document.documentElement;

      var scrollTop = window.pageYOffset || docEl.scrollTop || body.scrollTop;
      var clientTop = docEl.clientTop || body.clientTop || 0;
      var top = box.top + (scrollTop - clientTop) - 56;

      this.content.scrollTo(0, top, 500);
    }
  }

Do the scrolling call:

this.scrollTo("page-header");

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to scroll to top at each page change on Pagination ...
I would like to have an automatic scroll up when I change pages thanks to my Pagination component. It works great but I...
Read more >
Scroll up on ngb pagination page click - Google Groups
I have below code where in my angular 6 application (pageChange)="loadPage($event)" , I am using loadPage method to scroll up in the table ......
Read more >
ngx-pagination v6.0.1 - GitHub Pages
pageChange [ event handler ] The expression specified will be invoked whenever the page changes via a click on one of the pagination...
Read more >
Scroll to the top of the page using JavaScript/jQuery
A scrollable page can be scrolled to the top using 2 approaches: Method 1: Using window. scrollTo(): The scrollTo() method of the window ......
Read more >
Virtual Scrolling - Grid - Kendo UI for Angular - Telerik
To define the virtual scrolling functionality, set scrollable to virtual . Generally, to determine when a pageChange event has to be fired so...
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