-
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 column.colSpan prop #2356
Add column.colSpan prop #2356
Conversation
Why not go for a non-manually calculated api? #2350 |
@ekeuus |
@@ -279,6 +289,14 @@ function DataGrid<R, SR>({ | |||
enableVirtualization | |||
}); | |||
|
|||
const viewportColumns = useViewportColumns({ |
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.
Had to split into two hooks as we need to calculate colspan for all the rows in the viewport. This is needed to ensure a column that spans a column in the viewport is also visible
src/HeaderRow.tsx
Outdated
return ( | ||
<div | ||
role="row" | ||
aria-rowindex={1} // aria-rowindex is 1 based | ||
className={headerRowClassname} | ||
> | ||
{columns.map(column => { | ||
if (colSpan && colSpan > 1) { |
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.
Do not render cells in the colspan range
@@ -0,0 +1,252 @@ | |||
import { useMemo } from 'react'; |
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.
Same as previous useViewportColumns
hook. I moved the last useMemo
to the new useViewportColumns
hook as it needs rows
src/utils/index.ts
Outdated
return colSpan; | ||
} | ||
|
||
function areColSpanColumnsCompatible<R, SR>(column: CalculatedColumn<R, SR>, viewportColumns: readonly CalculatedColumn<R, SR>[], colSpan: 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.
Ensure all the columns within the colspan range are either frozen or not
Co-authored-by: Nicolas Stepien <[email protected]>
Co-authored-by: Nicolas Stepien <[email protected]>
Co-authored-by: Nicolas Stepien <[email protected]>
Co-authored-by: Nicolas Stepien <[email protected]>
Co-authored-by: Nicolas Stepien <[email protected]>
Co-authored-by: Nicolas Stepien <[email protected]>
Co-authored-by: Nicolas Stepien <[email protected]>
Co-authored-by: Nicolas Stepien <[email protected]>
Co-authored-by: Nicolas Stepien <[email protected]>
Co-authored-by: Nicolas Stepien <[email protected]>
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.
Maybe now is a good time to update the PR title
* Add column.colSpan prop * Change colSpan signature * Handle keyboard navigation * Add comments * Update example * Handle frozen columns * Handle header and summary rows * Update example * Update viewport columns to handle colspan * Add ColumnSpanning example * Cleanup cell selection logic * Update src/utils/index.ts Co-authored-by: Nicolas Stepien <[email protected]> * Update src/utils/index.ts Co-authored-by: Nicolas Stepien <[email protected]> * Remove unused import * Check integer and non negative values * Move to cell selection logic to DataGrid * Update src/utils/index.ts Co-authored-by: Nicolas Stepien <[email protected]> * Tweak colors * Fix eslint warning * Split into two useMemos, fix startIdx * Check header and summary rows * Fix next position logic * Make sure cell is within bounds * Loop through columns once * Do not close flighting editor on enter/escape * Revert "Do not close flighting editor on enter/escape" This reverts commit fc6ed3d. * Add cellSpan tests * Remove colSpan number type * Optimize colSpan check * Test navigation * Fix types * Check filter row * Fix types * Update src/hooks/useCalculatedColumns.ts Co-authored-by: Nicolas Stepien <[email protected]> * Update src/hooks/useViewportColumns.ts Co-authored-by: Nicolas Stepien <[email protected]> * Update src/hooks/useViewportColumns.ts Co-authored-by: Nicolas Stepien <[email protected]> * Update src/types.ts Co-authored-by: Nicolas Stepien <[email protected]> * Update src/hooks/useViewportColumns.ts Co-authored-by: Nicolas Stepien <[email protected]> * Update src/hooks/useViewportColumns.ts Co-authored-by: Nicolas Stepien <[email protected]> * Update src/hooks/useViewportColumns.ts Co-authored-by: Nicolas Stepien <[email protected]> * Quit loop when first startIdx is found * Re-export ColSpanArgs * Use lastFrozenColumnIndex to validate colSpan * Update src/hooks/useViewportColumns.ts Co-authored-by: Nicolas Stepien <[email protected]> * Update src/utils/index.ts Co-authored-by: Nicolas Stepien <[email protected]> * Update test/column/colSpan.test.ts Co-authored-by: Nicolas Stepien <[email protected]> * Update test/column/colSpan.test.ts Co-authored-by: Nicolas Stepien <[email protected]> * Add getCellsAtRowIndex util * Move nextPosition calculation logic to getNextSelectedCellPosition * column.colSpan can't be a number * Eslint * Typecheck * Reuse colIdx, add posIdx * Move posIdx outside * Add failing tests * Fix cell navigation Co-authored-by: Nicolas Stepien <[email protected]>
It can be used as