admin管理员组文章数量:1432001
I am using antd table pagination and i want to custom the pagination. Data inside table will be retrieved 50 records/API call. Data inside table will be displayed 10 records/page. next button on pagination will be enabled if there are remaining data in the system but not being retrieved yet, and will be disabled otherwise. E.g. there are 100 records in system. First API call will get 50 latest records (no 100 – 50) and will be rendered into the table. Since one page will display 10 records, it will be in 5 pages. After user arrived in page 5, the next button will be available because there are remaining 50 records in the system. If user click the next, API will be called for the second time and data inside the table will appended and total page will be 10 because, all of data has been retrieved. next button will disabled after the second API call and user only able to go to page 10 for the last page.
suggest me a suitable approach.
<Table
columns={columns}
dataSource={tableinfo.data_source}
pagination={false}
/>
<Pagination
total={500}
itemRender={itemRender}
/>
const itemRender = (current, type, originalElement) => {
if (type === 'prev') {
return <a>Previous</a>;
}
if (type === 'next') {
return <a>Next</a>;
}
return originalElement;
}
I am using antd table pagination and i want to custom the pagination. Data inside table will be retrieved 50 records/API call. Data inside table will be displayed 10 records/page. next button on pagination will be enabled if there are remaining data in the system but not being retrieved yet, and will be disabled otherwise. E.g. there are 100 records in system. First API call will get 50 latest records (no 100 – 50) and will be rendered into the table. Since one page will display 10 records, it will be in 5 pages. After user arrived in page 5, the next button will be available because there are remaining 50 records in the system. If user click the next, API will be called for the second time and data inside the table will appended and total page will be 10 because, all of data has been retrieved. next button will disabled after the second API call and user only able to go to page 10 for the last page.
suggest me a suitable approach.
<Table
columns={columns}
dataSource={tableinfo.data_source}
pagination={false}
/>
<Pagination
total={500}
itemRender={itemRender}
/>
const itemRender = (current, type, originalElement) => {
if (type === 'prev') {
return <a>Previous</a>;
}
if (type === 'next') {
return <a>Next</a>;
}
return originalElement;
}
Share
Improve this question
asked Jan 19, 2022 at 4:28
mohit guptamohit gupta
1732 gold badges4 silver badges13 bronze badges
1 Answer
Reset to default 2The easiest way is to define local states for pageSize
and pageIndex
.
Assuming that you have an api that returns the total hit count of elements the antd pagination can handle the described button behavior without any additional changes to your code.
For example: you want to fetch page 2
with a page size of 10
and there are 123 elements in total
{
results, // Array containing elements 20-30
hitCount // 123
}
Your code could look like
const [pageIndex, setPageIndex] = useState(0);
const [pageSize, setPageSize] = useState(10);
const hitCount = <obtained from the api call>
...
<Pagination current={pageIndex} total={hitcount} onChange={(page, size) => {setPageIndex(page); setPageSize(size)}} />
本文标签: javascripthow to use custom pagination in antd table in reactStack Overflow
版权声明:本文标题:javascript - how to use custom pagination in antd table in react? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745545433a2662682.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论