@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
106 lines (105 loc) • 3.01 kB
JavaScript
/**
* @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, createLocalDataState as M, createDataTree as q, createFlatSchemaDimensions as z } from "@progress/kendo-pivotgrid-common";
const G = "aggregate", H = "columns", f = { dataField: G, columnsData: H }, i = "&", I = (e) => {
const [m, h] = t.useState(!0), [a, v] = t.useState(e.defaultColumnAxes || []), [o, D] = t.useState(e.defaultRowAxes || []), [d, F] = t.useState(e.defaultMeasureAxes || []), [n, R] = t.useState(e.defaultSort || []), [S, T] = t.useState(e.defaultFilter || []), [b, k] = t.useState(/* @__PURE__ */ new Map()), g = t.useCallback((s) => {
D(s.value);
}, []), p = t.useCallback((s) => {
v(s.value);
}, []), L = (s) => {
F(s.value);
}, P = (s) => {
R(s.value);
}, y = (s) => {
T(s.value);
}, A = t.useMemo(
() => Array.from(w(a).keys()).join(i),
[a]
), x = t.useMemo(() => Array.from(w(o).keys()).join(i), [o]), u = t.useCallback(
(s) => ({ key: s, ...e.dimensions[s] }),
[e.dimensions]
), r = t.useMemo(
() => A ? A.split(i).map(u) : [],
[A, u]
), l = t.useMemo(
() => x ? x.split(i).map(u) : [],
[x, u]
), c = t.useMemo(
() => d.map((s) => e.measures.find((E) => String(E.name) === String(s.name))).filter(Boolean),
[d, e.measures]
), [C, j] = t.useState(
M({
dataTree: b,
rowSettings: l,
columnSettings: r,
rowAxes: o,
columnAxes: a,
measures: c,
sort: n,
fields: f
})
);
t.useEffect(() => {
h(!0), setTimeout(() => {
const s = new Map(
q(e.data, l, r, c, f, S)
);
k(s), j(
M({
dataTree: s,
rowSettings: l,
columnSettings: r,
rowAxes: o,
columnAxes: a,
measures: c,
sort: n,
fields: f
})
), h(!1);
}, 0);
}, [e.data, l, r, c, S, o, a, n]);
const B = t.useMemo(
() => z(e.dimensions, e.measures),
[e.dimensions, e.measures]
);
return {
pivotProps: {
rowAxes: o,
columnAxes: a,
data: C.data,
rows: C.rows,
columns: C.columns,
onRowAxesChange: g,
onColumnAxesChange: p
},
configuratorProps: {
sort: n,
onSortChange: P,
filter: S,
onFilterChange: y,
data: B,
rowAxes: o,
columnAxes: a,
measureAxes: d,
onRowAxesChange: g,
onColumnAxesChange: p,
onMeasureAxesChange: L
},
state: {
loading: m
}
};
}, K = (e) => {
const m = I(e);
return e.children(m);
};
export {
K as PivotLocalDataService,
I as usePivotLocalDataService
};