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.

Setting new items results in a re-submit of server-side paging

See original GitHub issue

Angular version: 2.4.4

ngx-pagination version: 3.0.0

Description of issue: When new items are set in a list that is being paginated, and the total items are fewer than those shown on the current page, ngx-pagination switches pages and emits a “pageChange” event. In the case of server-side paging, this results in re-submitting the server-side request.

Steps to reproduce: For example: The user searches on server and receives the first 10 items of a 20-result set (totalItems: 20, itemsPerPage: 10). The user jumps to the second page and a request is made to fetch the second set of 10 items. Finally, the user executes a new search that only contains a total of 8 items. This results in ngx-pagination switching to page one, thereby triggering a “pageChange” event and triggering a second, unwanted backend paging request.

Expected result: When setting new items in a list that have fewer totalItems than the previous set of items, the page should be changed but no pageChange event should be emitted. Alternatively, there should be two types of pageChange events, one for user-triggered page changes and one for page changes that are automatically executed due to changes in totalItems.

Actual result: A second, unwanted server paging request is executed.

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

Any relevant code:

<pagination-template #p="paginationApi"
                     [id]="id"
                     (pageChange)="onPageChange($event)"><!--executes server request-->

    <div>
        <!-- pagination -->
        <ul class="pagination" *ngIf="p.getLastPage() > 1">
            <li [ngClass]="{disabled: p.isFirstPage()}"><a (click)="p.setCurrent(1)">«</a></li>
            <li [ngClass]="{disabled: p.isFirstPage()}"><a (click)="p.previous()" >‹</a></li>

            <li *ngFor="let page of p.pages" [ngClass]="{active: page.value === p.getCurrent()}" [class.current]="p.getCurrent() === page.value">
                <a (click)="p.setCurrent(page.value)">
                    <span>{{ page.label }}</span>
                </a>
            </li>

            <li [ngClass]="{disabled: p.isLastPage()}"><a (click)="onNext(p)">›</a></li>
            <li [ngClass]="{disabled: p.isLastPage()}"><a (click)="p.setCurrent(p.getLastPage())">»</a></li>
        </ul>
        <!-- ~~~~~~~~ -->
    </div>

</pagination-template>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
michaelbromleycommented, Dec 2, 2019

@jtan80813 yes, this is now published on npm.

0reactions
michaelbromleycommented, Dec 2, 2019

Fixed in v5.0.0!

Note that this is a breaking change. See Changelog for more details: https://github.com/michaelbromley/ngx-pagination/blob/master/CHANGELOG.md#500-2019-12-02

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Server side paging when result is always paginated
SOLVED. New router. Northwind.CustomersRoute = Ember.Route.extend({ model: function () { var controller = this.controllerFor('customer'); return ...
Read more >
Set Up Server-Side Paging and Sorting for a Microflow Data ...
6.2 Disabling Server-Side Sorting · Open the page containing the data grid. · Right-click the data view surrounding the data grid and select...
Read more >
Add sorting, filtering, and paging - ASP.NET MVC with EF Core
In this tutorial you'll add sorting, filtering, and paging functionality ... This code uses the information in ViewData properties to set up ......
Read more >
Pagination in the REST API - Atlassian Developer
For that reason, we paginate the results to make sure responses are easier to handle. ... in this call is set to 5,...
Read more >
DataTables example - Server-side processing
As such, each draw of the table will result in a new Ajax request being made to get the required data. Server-side processing...
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