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] Fix first row flickering with autoHeight enabled #14235

Merged
merged 8 commits into from
Aug 30, 2024
4 changes: 4 additions & 0 deletions docs/data/data-grid/virtualization/virtualization.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Row virtualization is the insertion and removal of rows as the data grid scrolls
The grid renders some additional rows above and below the visible rows. You can use `rowBufferPx` prop to hint to the Data Grid the area to render, but this value may not be respected in certain situations, for example during high-speed scrolling.
Row virtualization is limited to 100 rows in the `DataGrid` component.

:::warning
Row virtualization does not work with the `autoHeight` prop enabled.
:::

## Column virtualization

Column virtualization is the insertion and removal of columns as the data grid scrolls horizontally.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
import { useGridApiMethod } from '../../utils/useGridApiMethod';
import { GridStateInitializer } from '../../utils/useGridInitializeState';

type RootProps = Pick<DataGridProcessedProps, 'disableVirtualization'>;
type RootProps = Pick<DataGridProcessedProps, 'disableVirtualization' | 'autoHeight'>;

export type GridVirtualizationState = {
enabled: boolean;
Expand All @@ -22,7 +22,7 @@ export const EMPTY_RENDER_CONTEXT = {

export const virtualizationStateInitializer: GridStateInitializer<RootProps> = (state, props) => {
const virtualization = {
enabled: !props.disableVirtualization,
enabled: !props.disableVirtualization && !props.autoHeight,
KenanYusuf marked this conversation as resolved.
Show resolved Hide resolved
enabledForColumns: true,
renderContext: EMPTY_RENDER_CONTEXT,
};
Expand Down Expand Up @@ -74,7 +74,7 @@ export function useGridVirtualization(

/* eslint-disable react-hooks/exhaustive-deps */
React.useEffect(() => {
setVirtualization(!props.disableVirtualization);
}, [props.disableVirtualization]);
setVirtualization(!props.disableVirtualization && !props.autoHeight);
}, [props.disableVirtualization, props.autoHeight]);
/* eslint-enable react-hooks/exhaustive-deps */
}
Loading