@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
79 lines (78 loc) • 3.35 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 { TreeViewItemPropsContext as A, TreeView as V } from "@progress/kendo-react-treeview";
import { useCustomComponent as h, canUseRef as D } from "@progress/kendo-react-common";
import { extractDefaultFields as d, flatMap as R, recursiveMap as f } from "../utils/index.mjs";
import { PivotGridConfiguratorEditorStateContext as T } from "../shared/PivotGridConfiguratorEditorStateContext.mjs";
const b = t.forwardRef(
(r, I) => {
const { data: p, rowAxes: x, columnAxes: C, measureAxes: v, onExpand: o, onCheck: s } = { ...m, ...r }, i = t.useRef(null), n = t.useRef(null), [l, g] = h(
r.treeView || m.treeView
), [E, y] = h(r.noData || m.noData);
t.useImperativeHandle(n, () => ({ props: r, element: i.current && i.current.element })), t.useImperativeHandle(
I,
() => n.current
);
const [N] = t.useContext(T), w = d(C), k = d(x), H = d(v), q = R(p).filter(
(e) => [...w, ...k, ...H].some(
(a) => a === e.uniqueName || a === e.defaultHierarchy
)
), u = {
caption: (e) => e.dataItem.caption,
id: (e) => e.dataItem.uniqueName,
value: (e) => e.dataItem.defaultHierarchy || e.dataItem.uniqueName,
expanded: (e) => N.expanded.some((a) => a.uniqueName === e.dataItem.uniqueName),
hasChildren: (e) => !("hierarchyUniqueName" in e.dataItem) && !("aggregator" in e.dataItem),
selectable: (e) => !(!e.hasChildren && !e.dataItem.aggregator && !e.dataItem.measure || e.dataItem.type === 2 || e.dataItem.uniqueName === "[KPIs]"),
children: (e) => f(e.dataItem.children, u, e),
checked: (e) => q.some(
(a) => e.dataItem.defaultHierarchy ? a.defaultHierarchy === e.dataItem.defaultHierarchy : a.uniqueName === e.dataItem.uniqueName
) || e.children.length && e.children.every((a) => a.checked)
}, F = (e) => {
o && o({
value: e.item.dataItem,
target: n.current,
syntheticEvent: e.syntheticEvent
});
}, P = (e) => {
s && s({
value: e.item.dataItem,
target: n.current,
syntheticEvent: e.syntheticEvent
});
}, c = f(r.data, u);
return /* @__PURE__ */ t.createElement(A.Provider, { value: (e) => ({ ...e, checkboxes: e.item.selectable }) }, c && c.length ? /* @__PURE__ */ t.createElement(
l,
{
ref: D(l) ? i : void 0,
data: c,
checkboxes: !0,
onExpandChange: F,
onCheckChange: P,
textField: "caption",
expandIcons: !0,
hasChildrenField: "hasChildren",
checkIndeterminateField: "checkIndeterminate",
childrenField: "children",
...g
}
) : /* @__PURE__ */ t.createElement(E, { ...y }));
}
), m = {
data: [],
rowAxes: [],
columnAxes: [],
measureAxes: [],
treeView: V,
noData: () => /* @__PURE__ */ t.createElement("div", null, "NO DATA")
};
b.displayName = "KendoReactPivotGridFieldsEditor";
export {
b as PivotGridFieldsEditor
};