@mui/x-data-grid
Version:
The community edition of the data grid component (MUI X).
40 lines (35 loc) • 991 B
JavaScript
import { GRID_DEFAULT_STRATEGY, useGridRegisterStrategyProcessor } from '../../core/strategyProcessing';
const flatRowTreeCreationMethod = ({
ids,
idRowsLookup,
idToIdLookup,
previousTree
}) => {
const tree = {};
for (let i = 0; i < ids.length; i += 1) {
const rowId = ids[i];
if (previousTree && previousTree[rowId] && previousTree[rowId].depth === 0 && previousTree[rowId].parent == null && // pinned row can be unpinned
!previousTree[rowId].isPinned) {
tree[rowId] = previousTree[rowId];
} else {
tree[rowId] = {
id: rowId,
depth: 0,
parent: null,
groupingKey: '',
groupingField: null
};
}
}
return {
groupingName: GRID_DEFAULT_STRATEGY,
tree,
treeDepth: 1,
idRowsLookup,
idToIdLookup,
ids
};
};
export const useGridRowsPreProcessors = apiRef => {
useGridRegisterStrategyProcessor(apiRef, GRID_DEFAULT_STRATEGY, 'rowTreeCreation', flatRowTreeCreationMethod);
};