swimlane / ngx-datatable

✨ A feature-rich yet lightweight data-table crafted for Angular
http://swimlane.github.io/ngx-datatable/
MIT License
4.62k stars 1.68k forks source link

Table footer page number is not resetting after setting the offset #883

Open devany1 opened 6 years ago

devany1 commented 6 years ago

I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, post on Stackoverflow or Gitter

Current behavior Table footer page number is not resetting after setting the offset

Expected behavior Table footer page number should change after setting the offset

Reproduction of the problem I have implemented the server side paging and sorting in my application. following is the sample markup of my table <ngx-datatable

lntable

            class="material striped"
            [rows]="rows"
            [columnMode]="'flex'"
            [headerHeight]="40"
            [footerHeight]="50"
            [rowHeight]="'auto'"
            [externalPaging]="true"
            [externalSorting]="true"
            [count]="page.totalElements"
            [offset]="page.pageNumber"                                
            [limit]="page.size"
            (page)="setPage($event)"
            (sort)="onSort($event)">                
    <ngx-datatable-column name="Mgr" prop="Mgr" [flexGrow]="1"></ngx-datatable-column>
    <ngx-datatable-column name="Client" prop="Client" [flexGrow]="1"></ngx-datatable-column>        
    <ngx-datatable-column name="Suppress" prop="Suppress" headerClass="ngx-align-center" [cellClass]="getCellClass" [flexGrow]="1"></ngx-datatable-column>      
    <ngx-datatable-column name="Remarks" prop="Remarks" [flexGrow]="2"></ngx-datatable-column>                        
</ngx-datatable>

I have imported the datatable component in my component class as follows

import { DatatableComponent } from '@swimlane/ngx-datatable/src/components/datatable.component';

@ViewChild('lntable') lntable: DatatableComponent;

If the user try to go to another page by clicking on the page number in footer. I am asking a confirmation in the setPage method as follows

setPage(pageInfo){     

    let userChoice = confirm('Do you want to continue?')
    if(userChoiceSort === false){                       
        this.lntable.offset = this.page.pageNumber;                
        return false;
    }       

    this.page.pageNumber = pageInfo.offset;
    this.service.getData(this.page).subscribe(pagedData => {
    this.page = pagedData.page;
    this.rows = pagedData.data;        
    });    

}

if user cancel the confirmation, I am setting the offset but on the UI, footer page number shows the clicked page as highlighted.

What is the motivation / use case for changing the behavior? Table footer page number should reset after setting the offset

Please tell us about your environment: Windows

harvanchik commented 3 years ago

I believe to be having this problem now in Angular 10.

So it appears to be happening only when the page it is manually being set back to is the same page the user is navigating from.

For example, let's say I want the table to always navigate to page 5 when the user uses the arrow buttons in the footer. When starting on page 1, if I use the right arrow, it sends the table to page 5. This works correctly. Now the problem comes when trying to navigate away from page 5. When I click the arrow to navigate to the last page of the table, it navigates to the last page instead of staying on page 5. When navigating to the last page from any other page than page 5, it navigates to page 5.