Skip to content

New API: onScrollEndReached (x/y) #5

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

Open
alexkrolick opened this issue Jan 15, 2018 · 17 comments
Open

New API: onScrollEndReached (x/y) #5

alexkrolick opened this issue Jan 15, 2018 · 17 comments

Comments

@alexkrolick
Copy link
Contributor

A prop that takes a callback for reaching the end of the scrolling area would be useful for infinite scroll/autopagination

@scamden
Copy link
Member

scamden commented Jan 18, 2018

actually the grid's default data-model can handle scroll virtualized to the server. the suggested model is to load just id's to represent each row or at least to know the row count ahead of time (even with huge data sets this is usually doable) and then fetch the full objects as the grid asks for them. the ReactGrid takes a loadRows prop which is (rowIndexes : number[]) => void and expects you to populate the data for those rowIndexes if that makes sense. (the indexes are in the data space, that is to say they don't include the header)

@scamden
Copy link
Member

scamden commented Jan 18, 2018

if you really want to do something on scroll the grid does fire numerous events through it's eventLoop; one is 'grid-cell-scroll'. currently this has to be bound directly through the grid object but i have been considering adding event props like react does (on-grid-cell-scroll={} etc)

@alexkrolick
Copy link
Contributor Author

Ok, I can look into loadRows; however, a prop that fires when the end is reached is more useful in the case where the full number of rows is unknown or only known approximately.

@scamden
Copy link
Member

scamden commented Jan 23, 2018 via email

@yashshah12
Copy link

Hey, I am a colleague of @alexkrolick and I was wondering if there is a timeline as to when this feature will be into the next release?

@scamden
Copy link
Member

scamden commented Jan 23, 2018

well as i told @alexkrolick this feature is not the recommended way to virtualize the data in the grid, so i would strongly recommend taking the approach i mentioned near the top of this issue. if you're dead set on following a different approach i can prioritize this though as it won't take terribly long. let me know.

@alexkrolick
Copy link
Contributor Author

alexkrolick commented Jan 23, 2018

To clarify, is this how it works:

  1. Initial data load (total = total item count)
  2. Create row data structure for fetched data
  3. Fill in up to total with empty data
  4. Get ref to grid (see README)
  5. Attach loadRows to a function that fetches (endIndex - startIndex) more rows and changes the data in place (have to be careful with React's setState and immutability here I think).

What is the page size for the loadRows method? Is it configurable?

@scamden
Copy link
Member

scamden commented Jan 23, 2018

@alexkrolick that's close ya. there's no need for a grid ref or to fill empty data. you can do it like this

  1. initital data load get total item count
  2. create total row objects
  3. pass a function to loadRows prop that when called fetches the data associated with the supplied row indexes
  4. when the data comes back from the fetch either put it on the data field of the correct row object you created, or you can pass all the data you know about directly to the data prop of react grid as a two dimensional array where data[row][col] = gridDataResult;

The paging is an optimized algorithm that loosely tries to fetch twice the current viewport size (in rows). I'd be open to discussing tweaks to this, but it worked very nicely for us over at salesforceiq, so i'd recommend trying it first to see how it performs for you.

@alexkrolick
Copy link
Contributor Author

Oh, there's a loadRows prop 😁 ... https://github.com/gridgrid/grid-react-adapter#props-and-formats

The query is relatively expensive (it's filtered Elasticsearch data), so I think making fewer would be better.

@scamden
Copy link
Member

scamden commented Jan 23, 2018 via email

@scamden
Copy link
Member

scamden commented Jan 23, 2018

oh i see how it would be easy to miss in the types. the reactgridprops interface extends from the gridopts interface so it has every field there as a prop as well. i'll add it to the docs.

@alexkrolick
Copy link
Contributor Author

alexkrolick commented Jan 23, 2018

run the filter on the ids only query

We could do that, it's not a big change for us right now.

I can open a separate issue for infinite-scroll use cases, for now I think we can try this.

@scamden
Copy link
Member

scamden commented Jan 23, 2018 via email

@yashshah12
Copy link

Hey @scamden, I see the loadRows in the readme and I passed that props to the component, but it didnt call my function. I am just wondering if that function is implemented cause I am looking at your code, and I dont see that loadRows prop being used.

@scamden
Copy link
Member

scamden commented Jan 26, 2018 via email

@alexkrolick
Copy link
Contributor Author

It's not working because the extra rows aren't populated with ids. We'll take this offline and check back.

@scamden
Copy link
Member

scamden commented Jan 26, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants