-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add column.colSpan prop #2356
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
Conversation
Why not go for a non-manually calculated api? #2350 |
@ekeuus |
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
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 <567105+nstepien@users.noreply.github.com>
Co-authored-by: Nicolas Stepien <567105+nstepien@users.noreply.github.com>
Co-authored-by: Nicolas Stepien <567105+nstepien@users.noreply.github.com>
Co-authored-by: Nicolas Stepien <567105+nstepien@users.noreply.github.com>
Co-authored-by: Nicolas Stepien <567105+nstepien@users.noreply.github.com>
Co-authored-by: Nicolas Stepien <567105+nstepien@users.noreply.github.com>
Co-authored-by: Nicolas Stepien <567105+nstepien@users.noreply.github.com>
Co-authored-by: Nicolas Stepien <567105+nstepien@users.noreply.github.com>
Co-authored-by: Nicolas Stepien <567105+nstepien@users.noreply.github.com>
Co-authored-by: Nicolas Stepien <567105+nstepien@users.noreply.github.com>
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 <567105+nstepien@users.noreply.github.com> * Update src/utils/index.ts Co-authored-by: Nicolas Stepien <567105+nstepien@users.noreply.github.com> * 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 <567105+nstepien@users.noreply.github.com> * 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 <567105+nstepien@users.noreply.github.com> * Update src/hooks/useViewportColumns.ts Co-authored-by: Nicolas Stepien <567105+nstepien@users.noreply.github.com> * Update src/hooks/useViewportColumns.ts Co-authored-by: Nicolas Stepien <567105+nstepien@users.noreply.github.com> * Update src/types.ts Co-authored-by: Nicolas Stepien <567105+nstepien@users.noreply.github.com> * Update src/hooks/useViewportColumns.ts Co-authored-by: Nicolas Stepien <567105+nstepien@users.noreply.github.com> * Update src/hooks/useViewportColumns.ts Co-authored-by: Nicolas Stepien <567105+nstepien@users.noreply.github.com> * Update src/hooks/useViewportColumns.ts Co-authored-by: Nicolas Stepien <567105+nstepien@users.noreply.github.com> * 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 <567105+nstepien@users.noreply.github.com> * Update src/utils/index.ts Co-authored-by: Nicolas Stepien <567105+nstepien@users.noreply.github.com> * Update test/column/colSpan.test.ts Co-authored-by: Nicolas Stepien <567105+nstepien@users.noreply.github.com> * Update test/column/colSpan.test.ts Co-authored-by: Nicolas Stepien <567105+nstepien@users.noreply.github.com> * 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 <567105+nstepien@users.noreply.github.com>
It can be used as