-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
[core] Each feature hook should be responsible for its column pre-processing #2839
[core] Each feature hook should be responsible for its column pre-processing #2839
Conversation
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Why you couldn't use?
We could check if the row is not null when rendering the rows. It worked with the diff below. Am I missing something? diff --git a/packages/grid/_modules_/grid/components/GridViewport.tsx b/packages/grid/_modules_/grid/components/GridViewport.tsx
index 863648e1..f5030398 100644
--- a/packages/grid/_modules_/grid/components/GridViewport.tsx
+++ b/packages/grid/_modules_/grid/components/GridViewport.tsx
@@ -71,24 +71,30 @@ export const GridViewport: ViewportType = React.forwardRef<HTMLDivElement, {}>(
renderState.renderContext.lastColIdx! + 1,
);
- return renderedRows.map(([id, row], idx) => (
- <rootProps.components.Row
- key={id}
- id={id}
- row={row}
- selected={selectionLookup[id] !== undefined}
- index={renderState.renderContext!.firstRowIdx! + idx}
- rowHeight={rowHeight}
- renderedColumns={renderedColumns}
- firstColumnToRender={renderState.renderContext!.firstColIdx!}
- cellFocus={cellFocus}
- cellTabIndex={cellTabIndex}
- editRowsModel={editRowsState}
- scrollBarState={scrollBarState}
- renderState={renderState}
- {...rootProps.componentsProps?.row}
- />
- ));
+ return renderedRows.map(([id, row], idx) => {
+ if (!row) {
+ return null;
+ }
+
+ return (
+ <rootProps.components.Row
+ key={id}
+ id={id}
+ row={row}
+ selected={selectionLookup[id] !== undefined}
+ index={renderState.renderContext!.firstRowIdx! + idx}
+ rowHeight={rowHeight}
+ renderedColumns={renderedColumns}
+ firstColumnToRender={renderState.renderContext!.firstColIdx!}
+ cellFocus={cellFocus}
+ cellTabIndex={cellTabIndex}
+ editRowsModel={editRowsState}
+ scrollBarState={scrollBarState}
+ renderState={renderState}
+ {...rootProps.componentsProps?.row}
+ />
+ );
+ });
};
return (
diff --git a/packages/grid/_modules_/grid/hooks/features/selection/useGridSelection.ts b/packages/grid/_modules_/grid/hooks/features/selection/useGridSelection.ts
index 3898b485..137c82ff 100644
--- a/packages/grid/_modules_/grid/hooks/features/selection/useGridSelection.ts
+++ b/packages/grid/_modules_/grid/hooks/features/selection/useGridSelection.ts
@@ -325,7 +325,7 @@ export const useGridSelection = (
[apiRef, props.checkboxSelectionVisibleOnly, props.pagination],
);
- useGridApiEventHandler(apiRef, GridEvents.visibleRowsSet, removeOutdatedSelection);
+ useGridApiEventHandler(apiRef, GridEvents.rowsSet, removeOutdatedSelection);
useGridApiEventHandler(apiRef, GridEvents.rowClick, handleRowClick);
useGridApiEventHandler(
apiRef, |
packages/grid/_modules_/grid/hooks/features/selection/useGridSelection.ts
Outdated
Show resolved
Hide resolved
packages/grid/_modules_/grid/hooks/core/columnsPreProcessing/useGridColumnsPreProcessing.ts
Show resolved
Hide resolved
Because
I probably works yes |
For now, listening to |
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.
It's worth to give a try on this approach to see where it goes.
OK to improve the reliability of the rows by doing this check. |
Closes #2814
Extracted from #2725
A side effect of using
registerColumnsPreProcessing
inuseGridSelection
was thatuseGridSelection
needed to be beforeuseGridColumns
.As a result, it could not use
const rowsLookup = useGridSelector(apiRef, gridRowsLookupSelector);
I migrated the selection cleanup when the rows update to an event.
But it can't be
GridEvents.rowsSet
, otherwise, this cleanup is triggered before the filtering and the rerender it causes seems to be synchronous.Basically here was the behavior with the exact same code but
useGridApiEventHandler(apiRef, GridEvents.rowsSet, removeOutdatedSelection);
on the testshould not crash when the row is removed during the click
apiRef.current.updateRows
GridEvents.rowsSet
is publisheduseGridSelection
updates its model because the selection row do not exist anymoreDataGrid
rerenders => Crashes because thevisibleRows
state still has the old deleted rowuseGridSorting
anduseGridFilter
updates their state without the deleted rowI fixed that by adding a
GridEvents.visibleRowsSet
thatuseGridFilter
triggers after updating the visible rows.