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.

Issue with multiple paginators in loop

See original GitHub issue

Hi,

Thanks for the awesome component. It is really helpful. I am facing issue in creating multiple paginators on single page. When I click the next button, it changes the page number for all instances. As per documentation, I am using unique id for each instance but facing same issue. Please find below code snippet. Here I am dynamically creating tables based based on “nodeName” received in first ngFor loop and then displaying data in each table (div) in each table in second ngFor loop. It displays the pagination for each table but on click of next button it moves to next page for all tables issue

I

<div style="display:inline-block;width:50%; padding-top:20px " *ngFor="let data of tabularData">
        <div class="">
          <div class="row dataFormatter">
            <div class="col-12 tabDataPadding dataheader">{{data.nodeName}}</div>
          </div>

          <div class="row table-bordered dataFormatter">
            <div class="col-4 tableBody tabDataPadding">Items</div>
            <div class="col-3 tableBody tabDataPadding">Value</div>
            <div class="col-5 tableBody tabDataPadding">Updated On</div>
          </div>
          <div class="row table-bordered dataFormatter" *ngFor="let tb of data.attributes | paginate: {id: data.nodeName, itemsPerPage:5 , currentPage:p }">
            <div class="col-4 tableBody tabDataPadding">{{tb.key}}</div>
            <div class="col-3 tableBody tabDataPadding">{{tb.value}}</div>
            <div style="font-size:0.9em" class="col-5 tabDataPadding tableBody">{{tb.date}}</div>
          </div>
          <pagination-controls id={{data.nodeName}} (pageChange)="p = $event"></pagination-controls>
    </div>
  </div>

=======

Angular version: 5.1.1

ngx-pagination version: 3.1

Description of issue:

Steps to reproduce:

Expected result:

Actual result:

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
michaelbromleycommented, May 24, 2018

Thanks for the link. I see the problem now.

You have only a single, shared variable p representing the current page. Each instance of pagination is therefore updating this shared variable, which then affects all other instances.

The solution is to use a unique currentPage variable for each instance. One way to do it is like this:

p: { [id: string]: number} = {};
<div *ngFor="let tb of data.attributes | paginate: {id: data.nodeName, itemsPerPage:3 , currentPage: p[data.nodeName] }">

<pagination-controls [id]='data.nodeName' (pageChange)="p[data.nodeName] = $event"></pagination-controls>

See this updated demo.

0reactions
akshay-borasecommented, May 25, 2018

Thanks Micheal. I will check it out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pagination problem with multiple loops on the same page
Is there a way to page the pagination aware of what the loop is and only scroll through that loop? Thanks in advance!...
Read more >
Wordpress: Multiple Custom Loop in One Page with Pagination
The answer from the following link allow you to have as many custom loops as you want all in the same page! https://wordpress.stackexchange.com/ ......
Read more >
Pagination Problem With Multiple Activity Loops on Same Page
I've created an aggregation page with two loops, each showing content from different types of users. The problem is that if I click...
Read more >
Multiple pagination on the same page - Laravel tips, tricks and ...
Multiple pagination on the same page - Laravel tips, tricks and packages · Comments • 18.
Read more >
Multiple channel loops without breaking pagination?
I want to break the loop into 2 sections in order to show an advertisement every 5 entries. So right now I have...
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