UNPKG

@progress/kendo-react-grid

Version:

React Data Grid (Table) provides 100+ ready-to-use data grid features. KendoReact Grid package

83 lines (82 loc) 3.2 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2026 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ import * as u from "react"; import { toCSVBlob as P } from "@progress/kendo-csv"; import { saveAs as R } from "@progress/kendo-file-saver"; import { process as j } from "@progress/kendo-data-query"; import { normalizeAutoProcessData as B, processData as D } from "./utils/dataProcessing.mjs"; const N = (e) => e && typeof e == "object" && "items" in e && "field" in e, K = (e) => e && typeof e == "object" && "data" in e ? e.data || [] : Array.isArray(e) ? e : [], V = (e, r) => r.split(".").reduce((t, a) => t == null ? void 0 : t[a], e), k = (e, r) => { const t = [], a = []; return e.length > 0 ? e.forEach(({ field: l, title: f }) => { t.push(l), a.push(f); }) : r.length > 0 && !Array.isArray(r[0]) && !N(r[0]) && Object.keys(r[0]).forEach((l) => { t.push(l), a.push(l); }), { autoKeys: t, autoNames: a }; }, F = (e, r) => e.map((t) => { const a = {}; return r.forEach((l) => { a[l] = V(t, l); }), a; }), H = u.forwardRef((e, r) => { const { gridProps: t, csv: a, fileName: l = "grid-export.csv", onCsvExport: f } = e, i = u.useMemo(() => typeof a == "object" && a !== null ? a : {}, [a]), d = u.useCallback(() => { var b, y; const p = i.data || t.data || []; let o = K(p); const g = f || t.onCsvExport; g && (o = g(o)); const A = i.allPages !== !1, h = B(t.autoProcessData); if (h) o = D(o, { autoProcessData: h, group: t.group, defaultGroup: t.defaultGroup, sort: t.sort, defaultSort: t.defaultSort, filter: t.filter, defaultFilter: t.defaultFilter, search: t.search, pageable: t.pageable, take: t.take, skip: t.skip, includePaging: !A }).data; else { const s = t.group || t.defaultGroup; s && s.length > 0 && (o = j(o, { group: s }).data); } const C = (e.columnsState || []).filter((s) => s.field && !s.hidden && s.show !== !1).map((s) => ({ field: s.field, title: s.title || s.field })); let n = (b = i.keys) != null ? b : void 0, c = (y = i.names) != null ? y : void 0; if (!n || !c) { const { autoKeys: s, autoNames: m } = k(C, o); n != null || (n = s.length > 0 ? s : void 0), c != null || (c = m.length > 0 ? m : void 0); } const E = n == null ? void 0 : n.some((s) => s.includes(".")), v = o.length > 0 && N(o[0]); E && !v && n && (o = F(o, n)); const S = v ? { data: o, total: o.length } : o, G = { ...i, data: S, keys: n, names: c }; return P(G); }, [t, i, f, e.columnsState]), x = u.useCallback(async () => { const p = d(), o = i.fileName || l; R(p, o); }, [i, l, d]); return u.useImperativeHandle(r, () => ({ save: x, getBlob: d })), null; }); H.displayName = "BaseCSVExport"; export { H as BaseCSVExport };