Skip to content

Commit

Permalink
[DataGrid] Make the pinned rows be on top of the no rows overlay (#9986)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanailH authored Sep 5, 2023
1 parent a77a7b2 commit 490bc5c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ const VirtualScrollerPinnedRows = styled('div', {
const boxShadowColor = getBoxShadowColor(theme);
return {
position: 'sticky',
// should be above the detail panel
zIndex: 3,
// should be above the no rows overlay
zIndex: 4,
backgroundColor: (theme.vars || theme).palette.background.default,
...(theme.vars
? { backgroundImage: theme.vars.overlays?.[2] }
Expand Down
30 changes: 24 additions & 6 deletions packages/grid/x-data-grid/src/components/base/GridOverlays.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { styled } from '@mui/system';
import {
unstable_composeClasses as composeClasses,
Expand All @@ -20,19 +21,24 @@ import { getDataGridUtilityClass } from '../../constants/gridClasses';
const GridOverlayWrapperRoot = styled('div', {
name: 'MuiDataGrid',
slot: 'OverlayWrapper',
shouldForwardProp: (prop) => prop !== 'overlayType',
overridesResolver: (props, styles) => styles.overlayWrapper,
})({
})<{ overlayType: 'loadingOverlay' | string }>(({ overlayType }) => ({
position: 'sticky', // To stay in place while scrolling
top: 0,
left: 0,
width: 0, // To stay above the content instead of shifting it down
height: 0, // To stay above the content instead of shifting it down
zIndex: 4, // Should be above pinned columns, pinned rows and detail panel
});
zIndex:
overlayType === 'loadingOverlay'
? 5 // Should be above pinned columns, pinned rows, and detail panel
: 4, // Should be above pinned columns and detail panel
}));

const GridOverlayWrapperInner = styled('div', {
name: 'MuiDataGrid',
slot: 'OverlayWrapperInner',
shouldForwardProp: (prop) => prop !== 'overlayType',
overridesResolver: (props, styles) => styles.overlayWrapperInner,
})({});

Expand All @@ -49,7 +55,7 @@ const useUtilityClasses = (ownerState: OwnerState) => {
return composeClasses(slots, getDataGridUtilityClass, classes);
};

function GridOverlayWrapper(props: React.PropsWithChildren<{}>) {
function GridOverlayWrapper(props: React.PropsWithChildren<{ overlayType: string }>) {
const apiRef = useGridApiContext();
const rootProps = useGridRootProps();

Expand Down Expand Up @@ -77,7 +83,7 @@ function GridOverlayWrapper(props: React.PropsWithChildren<{}>) {
}

return (
<GridOverlayWrapperRoot className={clsx(classes.root)}>
<GridOverlayWrapperRoot className={clsx(classes.root)} overlayType={props.overlayType}>
<GridOverlayWrapperInner
className={clsx(classes.inner)}
style={{
Expand All @@ -90,6 +96,14 @@ function GridOverlayWrapper(props: React.PropsWithChildren<{}>) {
);
}

GridOverlayWrapper.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
overlayType: PropTypes.string.isRequired,
} as any;

export function GridOverlays() {
const apiRef = useGridApiContext();
const rootProps = useGridRootProps();
Expand All @@ -102,22 +116,26 @@ export function GridOverlays() {
const showNoResultsOverlay = !loading && totalRowCount > 0 && visibleRowCount === 0;

let overlay: React.JSX.Element | null = null;
let overlayType = '';

if (showNoRowsOverlay) {
overlay = <rootProps.slots.noRowsOverlay {...rootProps.slotProps?.noRowsOverlay} />;
overlayType = 'noRowsOverlay';
}

if (showNoResultsOverlay) {
overlay = <rootProps.slots.noResultsOverlay {...rootProps.slotProps?.noResultsOverlay} />;
overlayType = 'noResultsOverlay';
}

if (loading) {
overlay = <rootProps.slots.loadingOverlay {...rootProps.slotProps?.loadingOverlay} />;
overlayType = 'loadingOverlay';
}

if (overlay === null) {
return null;
}

return <GridOverlayWrapper>{overlay}</GridOverlayWrapper>;
return <GridOverlayWrapper overlayType={overlayType}>{overlay}</GridOverlayWrapper>;
}

0 comments on commit 490bc5c

Please sign in to comment.