-
Notifications
You must be signed in to change notification settings - Fork 121
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
[sparkle] - feat(DataTable): implement virtual scrolling for DataTable component #11139
base: main
Are you sure you want to change the base?
Conversation
9c1290d
to
660be8b
Compare
sparkle/src/components/DataTable.tsx
Outdated
if (!tableWidth || !columns.length) { | ||
return columns.map((col) => ({ | ||
...col, | ||
size: col.size || 150, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No magic variable.
sparkle/src/components/DataTable.tsx
Outdated
const rowVirtualizer = useVirtualizer({ | ||
count: rows.length, | ||
getScrollElement: () => tableContainerRef.current, | ||
estimateSize: () => 50, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔
|
||
const observer = new IntersectionObserver( | ||
(entries) => { | ||
if (entries[0].isIntersecting && !isLoading) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's entries[0]
here? Last item? First item? I presume we want to load more when we reach close to the last item, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corresponds to the sentinel div at the bottom, will add a comment
sparkle/src/components/DataTable.tsx
Outdated
const columnSizing = React.useMemo(() => { | ||
return table.getAllColumns().reduce( | ||
(acc, column) => { | ||
acc[column.id] = column.getSize(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What size does this return?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same size as the one defined in columnsWithSize
- Added ScrollableDataTable to handle large data sets efficiently with virtualization - Integrated useVirtualizer to only render visible rows and improve performance - Implemented infinite scrolling with onLoadMore callback for fetching additional data - Included loading state with Spinner to indicate more data is being fetched - Adjusted column rendering logic to adapt to virtualized scrolling - Exposed ScrollableDataTable component and associated props for external use
- Removed hardcoded size in the virtualizer estimateSize in favor of a constant - Cleaned up redundant styles and attributes for DataTable components - Implemented a sensible algorithm for column size calculation when tableWidth is available - Adjusted rootMargin in IntersectionObserver for load more feature to "200% 0% 0% 0%" - Removed unnecessary mapping of columns in ScrollableDataTable that added default size - Updated DataTable stories to reflect new column sizing behavior
- Update the package-lock.json and package.json to reflect the new version release
- Implement dynamic column sizing based on the tableWidth and sizeRatio metadata for more flexible layouts - Change columnHeader height to 48px for better space utilization and adjust height class names to match Tailwind's naming scheme - Optimize column width allocation to ensure container width is fully utilized without exceeding it - Monitor table width changes to dynamically adjust column sizing for a responsive design - Remove column sorting handler from `DataTable.Head` component, possibly moving towards controlled component behavior - Update story examples to demonstrate new sizeRatio usage in column definitions for proportional widths
435a63e
to
d295a52
Compare
- Implement logic to ensure total column width matches table width - Remove unnecessary comments and clean up logic for setting column sizes
Description
Implements virtual scrolling for the
DataTable
component to improve performance when displaying large datasets. The virtual rendering optimizes the rendering process by only displaying rows that are currently visible in the viewport. This implementation leverages@tanstack/react-virtual
to handle the virtualization logic efficiently.References:
Risk
Low, new component
Deploy Plan
Publish sparkle