Skip to content

Commit

Permalink
[docs] Fix detail panel demo not working well with pinned columns (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
cherniavskii authored Oct 9, 2024
1 parent 59a9bef commit 68d4b75
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
18 changes: 12 additions & 6 deletions docs/data/data-grid/master-detail/FullWidthDetailPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,22 @@ import {
randomCommodity,
} from '@mui/x-data-grid-generator';

const getDetailPanelWidth = (gridDimensions) => {
return (
gridDimensions.viewportInnerSize.width +
gridDimensions.leftPinnedWidth +
gridDimensions.rightPinnedWidth
);
};

function DetailPanelContent({ row: rowProp }) {
const apiRef = useGridApiContext();
const [width, setWidth] = React.useState(() => {
const dimensions = apiRef.current.getRootDimensions();
return dimensions.viewportInnerSize.width;
});
const [width, setWidth] = React.useState(() =>
getDetailPanelWidth(apiRef.current.getRootDimensions()),
);

const handleViewportInnerSizeChange = React.useCallback(() => {
const dimensions = apiRef.current.getRootDimensions();
setWidth(dimensions.viewportInnerSize.width);
setWidth(getDetailPanelWidth(apiRef.current.getRootDimensions()));
}, [apiRef]);

React.useEffect(() => {
Expand Down
19 changes: 13 additions & 6 deletions docs/data/data-grid/master-detail/FullWidthDetailPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
useGridApiContext,
GridRowParams,
GRID_DETAIL_PANEL_TOGGLE_FIELD,
GridDimensions,
} from '@mui/x-data-grid-pro';
import {
randomCreatedDate,
Expand All @@ -22,16 +23,22 @@ import {
randomCommodity,
} from '@mui/x-data-grid-generator';

const getDetailPanelWidth = (gridDimensions: GridDimensions) => {
return (
gridDimensions.viewportInnerSize.width +
gridDimensions.leftPinnedWidth +
gridDimensions.rightPinnedWidth
);
};

function DetailPanelContent({ row: rowProp }: { row: Customer }) {
const apiRef = useGridApiContext();
const [width, setWidth] = React.useState(() => {
const dimensions = apiRef.current.getRootDimensions();
return dimensions.viewportInnerSize.width;
});
const [width, setWidth] = React.useState(() =>
getDetailPanelWidth(apiRef.current.getRootDimensions()),
);

const handleViewportInnerSizeChange = React.useCallback(() => {
const dimensions = apiRef.current.getRootDimensions();
setWidth(dimensions.viewportInnerSize.width);
setWidth(getDetailPanelWidth(apiRef.current.getRootDimensions()));
}, [apiRef]);

React.useEffect(() => {
Expand Down

0 comments on commit 68d4b75

Please sign in to comment.