-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Infinite scroll for Ant Table #5904
Comments
I don't think this feature should be included in antd. For it's hard to decide that which element's scroll events we should listen to. And you can implement this in your own component easily. |
Ok, since that's the case... I'm closing this issue for now. |
I would like this feature too or at least the capability to render more data dynamically. |
Wohoo, it is very easy to implement dynamic rows loading/infinite scrolling on antd table, I can chunk the httpRequest with this code:
|
@burhanmubarok , thanks for the snippet. |
@burhanmubarok thank you for a nice example, I'm starting to use this, but there are problems in some cases. For example, if my window height is 1000px, and I want to load 10 items per page/scroll, and height of each item is 50px, your example will not be working. Because scrollbar of tbody will not be rendered, I will be not able to scroll more. @afc163 this feature is very important, I think you need to implement it. I'm starting my third project with ant.design and have the same issue with this. |
@burubur Nice implementation. But it's actually a bad practice to get element with a css selector that's not in your control.
It's rational for a Table/List component to have a
I don't understand.
And don't just kick a feature request back to your user just because it's easy to implement. |
@hudidit |
@kappa-gooner maybe any suggestions for the case in ant examples? |
With @burubur's suggestion it does work but there are a couple user experience errors:
It would be great if the antd team would listen to this feature request. |
Any example on how to do this? |
should be a good workaround if set |
You can't, for now. There's no mechanism, as of yet, in antd to attach a ref to the Table component. It's hacky, but here's what I did... Query for the element and attach the scroll event listener useEffect(() => {
const node = document.querySelector<HTMLElement>(".table .ant-table-body");
if (node) {
node.addEventListener("scroll", () => {
const perc = (node.scrollTop / (node.scrollHeight - node.clientHeight)) * 100;
if (perc >= 100) {
console.log("TODO: Scrolling has reached bottom, load more data, or do whatever...");
}
});
}
}); Tell the table to NOT automatically reset the scroll position on dataSource change <Table
className="table"
scroll={{ scrollToFirstRowOnChange: false }}
...
/> A few things to note:
|
@xorander00 This is not working for me. Could you please help me with this? |
For those who are not able to get ref or find element by querySelector Try putting ref to upper Created a component to return ref:
and in our component
|
This infinite load is required and Pagination is not possible when data source is something like Firebase Firestore where the total number of documents is not known. In such case, either there should be this functionality of Infinite scroll-to-load or at least a "Load More" at the bottom like the Ant List. In current one, I've to implement a "Load more" feature. |
What problem does this feature solve?
As great as ant's pagination is, it is also something that is not very modern. I'd like to wrap the table in a infinite scroll that would make ajax request and fetch more rows upon scrolling (Refer here).
This is a simple example of creating such a table.
What does the proposed API look like?
To be honest, am not too sure at this point.
For a start we could wrap the Table in an
InfiniteLoader
HOC and have a event handler prop on the tableonScroll
that is triggered when the table is scrolled. The purpose of theInfiniteLoader
would be to help break large data sets down into chunks that could be just-in-time loaded as they were scrolled into view.I'll be happy to send forth a PR if you think this might be useful. If not, please feel free to close this item.
The text was updated successfully, but these errors were encountered: