Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

JulesBelveze
Copy link
Contributor

@JulesBelveze JulesBelveze commented Feb 28, 2025

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

@JulesBelveze JulesBelveze force-pushed the sparkle/revamp-datatable branch from 9c1290d to 660be8b Compare February 28, 2025 16:45
@JulesBelveze JulesBelveze requested a review from flvndvd February 28, 2025 16:48
if (!tableWidth || !columns.length) {
return columns.map((col) => ({
...col,
size: col.size || 150,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No magic variable.

const rowVirtualizer = useVirtualizer({
count: rows.length,
getScrollElement: () => tableContainerRef.current,
estimateSize: () => 50,
Copy link
Contributor

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

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

const columnSizing = React.useMemo(() => {
return table.getAllColumns().reduce(
(acc, column) => {
acc[column.id] = column.getSize();
Copy link
Contributor

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?

Copy link
Contributor Author

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

@JulesBelveze JulesBelveze requested a review from flvndvd March 2, 2025 07:18
 - 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
@JulesBelveze JulesBelveze force-pushed the sparkle/revamp-datatable branch from 435a63e to d295a52 Compare March 3, 2025 08:16
 - Implement logic to ensure total column width matches table width
 - Remove unnecessary comments and clean up logic for setting column sizes
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

Successfully merging this pull request may close these issues.

2 participants