@progress/kendo-vue-grid
Version:
122 lines (121 loc) • 3.44 kB
JavaScript
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2026 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
import { defineComponent as v } from "vue";
import { toCSVBlob as y } from "@progress/kendo-csv";
import { saveAs as h } from "@progress/kendo-file-saver";
import { process as b } from "@progress/kendo-data-query";
import { normalizeAutoProcessData as g, processData as A } from "./utils/dataProcessing.mjs";
const f = (e) => e && typeof e == "object" && "items" in e && "field" in e, S = (e) => e && typeof e == "object" && "data" in e ? e.data || [] : Array.isArray(e) ? e : [], x = (e, t) => {
const l = [], o = [];
return e.length > 0 ? e.forEach(({
field: n,
title: a
}) => {
l.push(n), o.push(a);
}) : t.length > 0 && !Array.isArray(t[0]) && !f(t[0]) && Object.keys(t[0]).forEach((n) => {
l.push(n), o.push(n);
}), {
autoKeys: l,
autoNames: o
};
}, C = (e, t, l) => {
const o = l.allPages !== !1, n = g(t.autoProcessData);
if (n)
return A(e, {
autoProcessData: n,
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: !o
}).data;
const a = t.group || t.defaultGroup;
return a && a.length > 0 ? b(e, {
group: a
}).data : e;
}, G = (e, t, l) => {
var a, s;
let o = (a = e.keys) != null ? a : void 0, n = (s = e.names) != null ? s : void 0;
if (!o || !n) {
const {
autoKeys: r,
autoNames: c
} = x(t, l);
o || o != null || (o = r.length ? r : void 0), n || n != null || (n = c.length ? c : void 0);
}
return {
keys: o,
names: n
};
}, F = /* @__PURE__ */ v({
name: "BaseCSVExport",
props: {
gridProps: {
type: Object,
required: !0
},
csv: {
type: [Boolean, Object],
default: void 0
},
fileName: {
type: String,
default: "grid-export.csv"
},
onCsvexport: {
type: Function,
default: void 0
},
columnsState: {
type: Array,
default: void 0
}
},
setup(e, {
expose: t
}) {
const l = () => {
const n = typeof e.csv == "object" && e.csv !== null ? e.csv : {}, a = n.data || e.gridProps.dataItems || [];
let s = S(a);
const r = e.onCsvexport;
r && (s = r(s)), s = C(s, e.gridProps, n);
const c = (e.columnsState || []).filter((u) => u.field && !u.hidden && u.show !== !1).map((u) => ({
field: u.field,
title: u.title || u.field
})), {
keys: i,
names: d
} = G(n, c, s), m = s.length > 0 && f(s[0]) ? {
data: s,
total: s.length
} : s, p = {
...n,
data: m,
keys: i,
names: d
};
return y(p);
};
return t({
save: () => {
const n = typeof e.csv == "object" && e.csv !== null ? e.csv : {}, a = l(), s = n.fileName || e.fileName || "grid-export.csv";
h(a, s);
},
getBlob: l
}), () => null;
}
});
export {
F as BaseCSVExport
};