UNPKG

@mui/x-data-grid-pro

Version:

The Pro plan edition of the MUI X Data Grid components.

82 lines 4.32 kB
import type { RefObject } from '@mui/x-internals/types'; import { type GridRowId, type GridTreeNode, type GridGroupNode, type GridRowTreeConfig, type GridKeyValue, type GridValidRowModel } from '@mui/x-data-grid'; import { type ReorderOperationType } from "./types.js"; import type { GridPrivateApiPro } from "../../../models/gridApiPro.js"; import { DataGridProProcessedProps } from "../../../models/dataGridProProps.js"; export { getNodePathInTree } from "../../../utils/tree/utils.js"; /** * Finds the closest cell element from the given event target. * If the target itself is a cell, returns it. * Otherwise, searches for the closest parent with 'cell' in its className. * @param target - The event target to start searching from * @returns The cell element or the original target if no cell is found */ export declare function findCellElement(target: EventTarget | null): Element; export declare function determineOperationType(sourceNode: GridTreeNode, targetNode: GridTreeNode): ReorderOperationType; export declare function calculateTargetIndex(sourceNode: GridTreeNode, targetNode: GridTreeNode, isLastChild: boolean, rowTree: Record<GridRowId, GridTreeNode>): number; export declare const collectAllLeafDescendants: (groupNode: GridGroupNode, tree: GridRowTreeConfig) => GridRowId[]; export declare const collectAllDescendants: (groupNode: GridGroupNode, tree: GridRowTreeConfig) => GridTreeNode[]; export declare const isDescendantOf: (possibleDescendant: GridTreeNode, ancestor: GridTreeNode, tree: GridRowTreeConfig) => boolean; export declare const updateDescendantDepths: (group: GridGroupNode, tree: GridRowTreeConfig, depthDiff: number) => void; /** * Finds an existing group node with the same groupingKey and groupingField under a parent. * * @param parentNode - The parent group node to search in * @param groupingKey - The grouping key to match * @param groupingField - The grouping field to match * @param tree - The row tree configuration * @returns The existing group node if found, null otherwise */ export declare function findExistingGroupWithSameKey(parentNode: GridGroupNode, groupingKey: GridKeyValue, groupingField: string, tree: GridRowTreeConfig): GridGroupNode | null; /** * Removes empty ancestor groups from the tree after a row move operation. * Walks up the tree from the given group, removing any empty groups encountered. * * @param groupId - The ID of the group to start checking from * @param tree - The row tree configuration * @param removedGroups - Set to track which groups have been removed * @returns The number of root-level groups that were removed */ export declare function removeEmptyAncestors(groupId: GridRowId, tree: GridRowTreeConfig, removedGroups: Set<GridRowId>): number; export declare function handleProcessRowUpdateError(error: any, onProcessRowUpdateError?: DataGridProProcessedProps['onProcessRowUpdateError']): void; /** * Handles batch row updates with partial failure tracking. * * This class is designed for operations that need to update multiple rows * atomically (like moving entire groups), while gracefully handling cases * where some updates succeed and others fail. * * @example * ```tsx * const updater = new BatchRowUpdater(apiRef, processRowUpdate, onError); * * // Queue multiple updates * updater.queueUpdate('row1', originalRow1, newRow1); * updater.queueUpdate('row2', originalRow2, newRow2); * * // Execute all updates * const { successful, failed, updates } = await updater.executeAll(); * * // Handle results * if (successful.length > 0) { * apiRef.current.updateRows(updates); * } * ``` */ export declare class BatchRowUpdater { private apiRef; private processRowUpdate; private onProcessRowUpdateError; private rowsToUpdate; private originalRows; private successfulRowIds; private failedRowIds; private pendingRowUpdates; constructor(apiRef: RefObject<GridPrivateApiPro>, processRowUpdate: DataGridProProcessedProps['processRowUpdate'] | undefined, onProcessRowUpdateError: DataGridProProcessedProps['onProcessRowUpdateError'] | undefined); queueUpdate(rowId: GridRowId, originalRow: GridValidRowModel, updatedRow: GridValidRowModel): void; executeAll(): Promise<{ successful: GridRowId[]; failed: GridRowId[]; updates: GridValidRowModel[]; }>; }