@mui/x-data-grid-pro
Version:
The Pro plan edition of the MUI X Data Grid components.
37 lines (36 loc) • 1.31 kB
JavaScript
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import * as React from 'react';
import { useGridEvent as addEventHandler, useGridApiMethod } from '@mui/x-data-grid';
import { useGridRegisterStrategyProcessor } from '@mui/x-data-grid/internals';
import { INITIAL_STATE, useGridDataSourceBasePro } from "./useGridDataSourceBasePro.js";
function getKeyPro(params) {
return JSON.stringify([params.filterModel, params.sortModel, params.groupKeys, params.start, params.end]);
}
export const dataSourceStateInitializer = state => {
return _extends({}, state, {
dataSource: INITIAL_STATE
});
};
const options = {
cacheOptions: {
getKey: getKeyPro
}
};
export const useGridDataSourcePro = (apiRef, props) => {
const {
api,
strategyProcessor,
events,
setStrategyAvailability
} = useGridDataSourceBasePro(apiRef, props, options);
useGridApiMethod(apiRef, api.public, 'public');
useGridApiMethod(apiRef, api.private, 'private');
useGridRegisterStrategyProcessor(apiRef, strategyProcessor.strategyName, strategyProcessor.group, strategyProcessor.processor);
Object.entries(events).forEach(([event, handler]) => {
addEventHandler(apiRef, event, handler);
});
React.useEffect(() => {
setStrategyAvailability();
}, [setStrategyAvailability]);
};