ng-zorro-antd icon indicating copy to clipboard operation
ng-zorro-antd copied to clipboard

`nz-table` does not show pagination when `nzData` is an empty array

Open DarrenDanielDay opened this issue 8 months ago • 4 comments

Reproduction link

https://stackblitz.com/edit/ng-zorro-antd-ivy-r8fnmf?file=src%2Fapp%2Fapp.component.ts

Steps to reproduce

Delete todo 4.

What is expected?

The pagination component should not be removed, and the pageIndex should be normalized to 1 automatically by the nz-pagination component. After the pageIndex changed to 1, it should display 3 records in page 1.

What is actually happening?

Then the nz-pagination component in nz-table is removed.

Environment Info
ng-zorro-antd 16.2.0
Browser Edge 118.0.2088.46

Is the current behavior expected? Relevant code stays unchanged for 3 years.

https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/components/table/src/table/table.component.ts#L110

DarrenDanielDay avatar Oct 17 '23 17:10 DarrenDanielDay

I think the current behavior is as expected. If you want to achieve the behavior you describe, you should use frontEnd pagination.

cxb1021 avatar Oct 18 '23 14:10 cxb1021

I think the current behavior is as expected. If you want to achieve the behavior you describe, you should use frontEnd pagination.

But in this example, we set nzTotal to 3, which implies data on other pages does exist. It's reasonable to show an empty table when nzData is an empty array but removing the nz-pagination component makes the user unable to switch to a different page. If this is expected, do you have any example or best practice for server pagination?

DarrenDanielDay avatar Oct 20 '23 15:10 DarrenDanielDay

There should be a fallback logic on the server if the requested page is empty.

In your example, after id 4 is deleted and a request for pageIndex: 2 is sent, the server should return something like

{
    total: 3,
    pageIndex: 1,
    pageSize: 3,
    data: [1, 2, 3 ]
}

And you should use pageIndex from the server in the frontend after that.

rppig42 avatar Oct 24 '23 05:10 rppig42

Explicitly, I need this for server side pagination. When we have total but still nzDate:[] for any one pagination option then do not hide pagination setup.

ankitpandeypagefreezer avatar Apr 10 '24 06:04 ankitpandeypagefreezer