UNPKG

@1771technologies/lytenyte-pro

Version:

Blazingly fast headless React data grid with 100s of features.

24 lines (23 loc) 798 B
import { useMemo } from "react"; import { computeField } from "@1771technologies/lytenyte-core/internal"; export function usePivotGroupFn(pivotMode, model) { const groupFn = useMemo(() => { const pivotRows = model?.rows; if (!pivotMode || !pivotRows?.length) return () => [null]; const fn = (row) => { const paths = []; for (const c of pivotRows) { const field = c.field ?? c.id; const value = field ? computeField(field, row) : null; if (value == null) paths.push(null); else paths.push(String(value)); } return paths; }; return fn; }, [model?.rows, pivotMode]); return groupFn; }