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

[DataGrid] Move virtualization logic to hook #3079

Merged
merged 1 commit into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
335 changes: 0 additions & 335 deletions packages/grid/_modules_/grid/components/GridVirtualScroller.tsx

This file was deleted.

15 changes: 11 additions & 4 deletions packages/grid/_modules_/grid/components/base/GridBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@ import { GridMainContainer } from '../containers/GridMainContainer';
import { GridAutoSizer } from '../GridAutoSizer';
import { GridOverlays } from './GridOverlays';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { GridVirtualScroller } from '../GridVirtualScroller';
import { useGridSelector } from '../../hooks/utils/useGridSelector';
import { gridSelectionStateSelector } from '../../hooks/features/selection/gridSelectionSelector';
import { gridDensityHeaderHeightSelector } from '../../hooks/features/density/densitySelector';
import { GridScrollArea } from '../GridScrollArea';

interface GridBodyProps {
children?: React.ReactNode;
VirtualScrollerComponent: React.JSXElementConstructor<
React.HTMLAttributes<HTMLDivElement> & {
ref: React.Ref<HTMLDivElement>;
selectionLookup: {};
disableVirtualization: boolean;
}
>;
}

function GridBody(props: GridBodyProps) {
const { children } = props;
const { children, VirtualScrollerComponent } = props;
const apiRef = useGridApiContext();
const rootProps = useGridRootProps();
const selection = useGridSelector(apiRef, gridSelectionStateSelector);
Expand Down Expand Up @@ -98,10 +104,10 @@ function GridBody(props: GridBodyProps) {
// In this case, let the container to grow whatever it needs.
height: size.height ? size.height - headerHeight : 'auto',
marginTop: headerHeight,
};
} as React.CSSProperties;

return (
<GridVirtualScroller
<VirtualScrollerComponent
ref={windowRef}
style={style}
selectionLookup={selectionLookup} // TODO pass it directly to the row via componentsProps
Expand All @@ -121,6 +127,7 @@ GridBody.propTypes = {
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
children: PropTypes.node,
VirtualScrollerComponent: PropTypes.elementType.isRequired,
} as any;

export { GridBody };
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { GridComponentProps } from '../../GridComponentProps';
import { useGridApiEventHandler } from '../../hooks/utils/useGridApiEventHandler';
import { GridEvents } from '../../constants/eventsConstants';
import { GridColumnHeaderParams } from '../../models/params/gridColumnHeaderParams';
import { RenderContext } from '../GridVirtualScroller';
import { RenderContext } from '../../hooks/features/virtualization/useGridVirtualScroller';
import { GridColumnHeaderItem } from './GridColumnHeaderItem';
import { gridFilterActiveItemsLookupSelector } from '../../hooks/features/filter/gridFilterSelector';
import { gridColumnMenuSelector } from '../../hooks/features/columnMenu/columnMenuSelector';
Expand Down
Loading