Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
160
Pagination affecting grid navigation
posted

This post (https://www.infragistics.com/community/forums/f/ignite-ui-for-angular/124741/igx-datagrid-move-selected-row-into-view) has a great answer to navigating to a specific record in an IGX data grid.  However, when the grid is paginated, it doesn't work.  If the record is not on the current page, nothing happens.  Is there a way to navigate to a record on a different page?

Right now, the best way I can find is use the exist sort, and search the records to find the right one, mathematically determine which page it is on, then go to that page and execute the grid.verticalScroll,scrollPosition.  Isw there a better way?

Parents
No Data
Reply
  • 2560
    Offline posted

    Hi Ted,

    It would seem that there is not an out-of-the box method to navigate the grid to a record on a different page. Additionally, by looking at a paginated grid, the row indexes start from 0 on each page, so using a “global” index would not work indeed. Having this in mind, you are on the right track to implementing this with the help of some calculations.

    What I can add to this approach, though, is that you do not have to manually set the scroll positions of the grid. It would suffice to set the paginator’s page to the calculated (0-based) number and then calculate the 0-based index of the target record on the target page and use the navigateTo method with it, for instance:

      ngAfterViewInit(): void {
        requestAnimationFrame(() => {
          const idx = 176; // not 0-based
          if (idx > this.paginator.page * this.paginator.perPage) {
            const newPage = Math.ceil(idx / this.grid1.perPage);
            this.grid1.page = newPage - 1;
    
    
            const newIdx = idx - this.paginator.perPage * this.paginator.page - 1; // in case the index -based, do not subtract 1 here;
            this.grid1.navigateTo(newIdx);
          } else {
            this.grid1.navigateTo(idx);
          }
        });
      }

    Here is a small sample demonstrating this suggestion. I hope it helps.

    Best regards,
    Bozhidara Pachilova

Children
No Data