NG-ZORRO / ng-zorro-antd

Angular UI Component Library based on Ant Design
https://ng.ant.design
MIT License
8.85k stars 3.9k forks source link

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

Open DarrenDanielDay opened 11 months ago

DarrenDanielDay commented 11 months ago

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

cxb1021 commented 11 months ago

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

DarrenDanielDay commented 11 months ago

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?

rppig42 commented 10 months ago

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.

ankitpandeypagefreezer commented 5 months ago

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.