-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add support for variable row heights #2384
Conversation
@@ -94,20 +94,79 @@ export function useViewportRows<R>({ | |||
} | |||
}, [expandedGroupIds, groupedRows, rawRows]); | |||
|
|||
const { totalRowHeight, getRowTop, getRowHeight, findRowIdx } = useMemo(() => { | |||
if (typeof rowHeight === 'number') { |
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.
This change does not impact the performance if rowHeight
is a number.
|
||
const rowPositions: ({ height: number; top: number })[] = []; | ||
let totalRowHeight = 0; | ||
// Calcule the height of all the rows upfront. This can cause performance issues |
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.
I did not notice any performance issues even on a large grid. Tried editing, colspan and a few other features. This can be slow if rowHeight
itself is expensive
return rowPositions[rowIdx].top; | ||
}, | ||
getRowHeight: (rowIdx: number) => rowPositions[rowIdx].height, | ||
findRowIdx(offset: number) { |
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.
Use binary search on a sorted array.
@@ -98,13 +98,13 @@ function createRows(): readonly Row[] { | |||
for (let i = 1; i < 10000; i++) { | |||
rows.push({ | |||
id: i, | |||
year: 2015 + faker.random.number(3), | |||
year: 2015 + faker.datatype.number(3), |
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.
faker.random
is deprecated
Working on tests but ready for review. |
Co-authored-by: Nicolas Stepien <[email protected]>
Co-authored-by: Nicolas Stepien <[email protected]>
Co-authored-by: Nicolas Stepien <[email protected]>
* Change rowHeight to a function to support variable row heights * Fix hooks order * Remove memo * Add a comment * Fix tests * Fix types * Cleanup * Use a single array * Fix pageup/pagedown * Update src/DataGrid.tsx Co-authored-by: Nicolas Stepien <[email protected]> * Update src/hooks/useViewportRows.ts Co-authored-by: Nicolas Stepien <[email protected]> * newScrollTop -> nextRowY * move/deduplicate getRowTop(rowIdx) and getRowHeight(rowIdx) calls outside the ifs * Validate rowIdx * Update src/hooks/useViewportRows.ts Co-authored-by: Nicolas Stepien <[email protected]> * Fix typo * Add rowHeight tests * typo Co-authored-by: Nicolas Stepien <[email protected]>
rowHeight
to anumber/function
to support variable row heightsrowHeight
is a numberI think this can really useful specially on readonly grids