UNPKG

@progress/kendo-react-pivotgrid

Version:

React PivotGrid (also called Pivot Table) can be data-bound to an OLAP service and customized extensively. KendoReact PivotGrid package

95 lines (94 loc) 2.81 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ import * as t from "react"; import { rootFields as w, createDataTree as j, createLocalDataState as B, createFlatSchemaDimensions as E } from "@progress/kendo-pivotgrid-common"; const q = "aggregate", z = "columns", p = { dataField: q, columnsData: z }, u = "&", G = (e) => { const [l, h] = t.useState(!0), [o, M] = t.useState(e.defaultColumnAxes || []), [a, v] = t.useState(e.defaultRowAxes || []), [r, D] = t.useState(e.defaultMeasureAxes || []), [c, F] = t.useState(e.defaultSort || []), [i, R] = t.useState(e.defaultFilter || []), [m, b] = t.useState({ data: [], rows: [], columns: [] }), f = t.useCallback((s) => { v(s.value); }, []), g = t.useCallback((s) => { M(s.value); }, []), k = (s) => { D(s.value); }, L = (s) => { F(s.value); }, P = (s) => { R(s.value); }, d = t.useMemo( () => Array.from(w(o).keys()).join(u), [o] ), S = t.useMemo(() => Array.from(w(a).keys()).join(u), [a]), n = t.useCallback( (s) => ({ key: s, ...e.dimensions[s] }), [e.dimensions] ), A = t.useMemo( () => d ? d.split(u).map(n) : [], [d, n] ), x = t.useMemo( () => S ? S.split(u).map(n) : [], [S, n] ), C = t.useMemo( () => r.map((s) => e.measures.find((T) => String(T.name) === String(s.name))).filter(Boolean), [r, e.measures] ); t.useEffect(() => { h(!0), setTimeout(() => { const s = new Map( j(e.data, x, A, C, p, i) ); b( B({ dataTree: s, rowSettings: x, columnSettings: A, rowAxes: a, columnAxes: o, measures: C, sort: c, fields: p }) ), h(!1); }, 0); }, [e.data, x, A, C, i, a, o, c]); const y = t.useMemo( () => E(e.dimensions, e.measures), [e.dimensions, e.measures] ); return { pivotProps: { rowAxes: a, columnAxes: o, data: m.data, rows: m.rows, columns: m.columns, onRowAxesChange: f, onColumnAxesChange: g }, configuratorProps: { sort: c, onSortChange: L, filter: i, onFilterChange: P, data: y, rowAxes: a, columnAxes: o, measureAxes: r, onRowAxesChange: f, onColumnAxesChange: g, onMeasureAxesChange: k }, state: { loading: l } }; }, I = (e) => { const l = G(e); return e.children(l); }; export { I as PivotLocalDataService, G as usePivotLocalDataService };