UNPKG

@progress/kendo-vue-grid

Version:
121 lines (120 loc) 3.37 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 { defineComponent as k, inject as I, createVNode as n } from "vue"; import { GridColumnMenuItem as a } from "./GridColumnMenuItem.mjs"; import { GridColumnMenuItemGroup as L } from "./GridColumnMenuItemGroup.mjs"; import { normalize as z } from "../interfaces/GridSortSettings.mjs"; import { provideLocalizationService as A } from "@progress/kendo-vue-intl"; import { sortAscending as d, messages as m, sortDescending as u } from "../messages/main.mjs"; import { sortAscSmallIcon as $, sortDescSmallIcon as M } from "@progress/kendo-svg-icons"; import { hasListener as G } from "@progress/kendo-vue-common"; const f = "asc", p = "desc", b = { true: { asc: { asc: "", desc: "desc" }, desc: { asc: "asc", desc: "" }, "": { asc: "asc", desc: "desc" } }, false: { asc: { asc: "asc", desc: "desc" }, desc: { asc: "asc", desc: "desc" }, "": { asc: "asc", desc: "desc" } } }, S = (e, o) => o ? o.findIndex((t) => t.field === e) : -1, h = (e, o) => !!(o && e > -1 && o[e].dir === f), g = (e, o) => !!(o && e > -1 && o[e].dir === p), _ = (e, o) => { const t = S(e, o); return g(t, o) || h(t, o); }, q = /* @__PURE__ */ k({ props: { sortable: [Boolean, Object], sort: { type: Array }, column: Object, onSortchange: Function, onClosemenu: Function }, inject: { kendoLocalizationService: { default: null } }, methods: { onAscClick(e) { this.onSort(e, f), this.$emit("closemenu"); }, onDescClick(e) { this.onSort(e, p), this.$emit("closemenu"); }, onSort(e, o) { if (e.preventDefault(), !G.call(this, "sortchange")) return; const { column: t, sortable: s, sort: v } = this.$props, { allowUnsort: C, mode: D } = z(s || !1, !1), r = (v || []).filter((c) => c.field === t.field)[0], i = b[C][r && r.dir || ""][o], l = D === "single" ? [] : (this.$props.sort || []).filter((c) => c.field !== t.field); i !== "" && t.field && l.push({ field: t.field, dir: i }), this.$emit("sortchange", l, { event: e, field: this.$props.column.field }); } }, setup() { return { kendoLocalizationService: I("kendoLocalizationService", {}) }; }, render() { const { sort: e, column: o } = this.$props, t = S(o.field, e), s = A(this); return n(L, null, { default: () => [n(a, { title: s.toLanguageString(d, m[d]), icon: "sort-asc-small", svgIcon: $, selected: h(t, e), onMenuitemclick: this.onAscClick }, null), n(a, { title: s.toLanguageString(u, m[u]), icon: "sort-desc-small", svgIcon: M, selected: g(t, e), onMenuitemclick: this.onDescClick }, null)] }); } }); export { q as GridColumnMenuSort, _ as sortGroupByField };