UNPKG

@mui/x-data-grid-premium

Version:

The Premium plan edition of the MUI X Data Grid Components.

35 lines (29 loc) 1.56 kB
'use client'; import * as React from 'react'; import { useIsCellEditable as useIsCellEditableCommunity } from '@mui/x-data-grid-pro/internals'; import { gridAggregationModelSelector } from "../aggregation/gridAggregationSelectors.js"; /** * Implementation of the cell editable condition hook of the Data Grid Premium */ export const useIsCellEditable = (apiRef, props) => { const isCellEditableCommunity = useIsCellEditableCommunity(); return React.useCallback(params => { const isCellEditable = isCellEditableCommunity(params); // If the cell is not editable by the community hook, return false immediately if (!isCellEditable) { return false; } // If the data source is not used or aggregation is disabled or both tree data and row grouping are disabled, return the community hook result if (!props.dataSource || props.disableAggregation || !props.treeData && props.disableRowGrouping) { return isCellEditable; } // If the cell is not a part of the aggregation model, return the community hook result const aggregationModelFields = Object.keys(gridAggregationModelSelector(apiRef)); if (!aggregationModelFields.includes(params.field)) { return isCellEditable; } // The cell is a part of the aggregation model and it is retrieved from the server-side data. // Allow editing only for the non-grouped rows. return params.rowNode.type !== 'group'; }, [apiRef, props.dataSource, props.treeData, props.disableAggregation, props.disableRowGrouping, isCellEditableCommunity]); };