UNPKG

@progress/kendo-react-grid

Version:

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

143 lines (142 loc) 5.21 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 { messages as c } from "./messages/index.mjs"; import { IntlService as u } from "@progress/kendo-react-intl"; const q = [ { text: "grid.filterAndLogic", operator: "and" }, { text: "grid.filterOrLogic", operator: "or" } ], E = { text: [ { text: "grid.filterContainsOperator", operator: "contains" }, { text: "grid.filterNotContainsOperator", operator: "doesnotcontain" }, { text: "grid.filterEqOperator", operator: "eq" }, { text: "grid.filterNotEqOperator", operator: "neq" }, { text: "grid.filterStartsWithOperator", operator: "startswith" }, { text: "grid.filterEndsWithOperator", operator: "endswith" }, { text: "grid.filterIsNullOperator", operator: "isnull" }, { text: "grid.filterIsNotNullOperator", operator: "isnotnull" }, { text: "grid.filterIsEmptyOperator", operator: "isempty" }, { text: "grid.filterIsNotEmptyOperator", operator: "isnotempty" } ], numeric: [ { text: "grid.filterEqOperator", operator: "eq" }, { text: "grid.filterNotEqOperator", operator: "neq" }, { text: "grid.filterGteOperator", operator: "gte" }, { text: "grid.filterGtOperator", operator: "gt" }, { text: "grid.filterLteOperator", operator: "lte" }, { text: "grid.filterLtOperator", operator: "lt" }, { text: "grid.filterIsNullOperator", operator: "isnull" }, { text: "grid.filterIsNotNullOperator", operator: "isnotnull" } ], date: [ { text: "grid.filterEqOperator", operator: "eq" }, { text: "grid.filterNotEqOperator", operator: "neq" }, { text: "grid.filterAfterOrEqualOperator", operator: "gte" }, { text: "grid.filterAfterOperator", operator: "gt" }, { text: "grid.filterBeforeOperator", operator: "lt" }, { text: "grid.filterBeforeOrEqualOperator", operator: "lte" }, { text: "grid.filterIsNullOperator", operator: "isnull" }, { text: "grid.filterIsNotNullOperator", operator: "isnotnull" } ], boolean: [{ text: "grid.filterEqOperator", operator: "eq" }] }, s = (t) => t === "isnull" || t === "isnotnull" || t === "isempty" || t === "isnotempty", h = (t, i) => t.map((e) => ({ text: i.toLanguageString(e.text, c[e.text]), operator: e.operator })), x = "eq", N = [ { text: "grid.filterBooleanAll", operator: "" }, { text: "grid.filterIsTrue", operator: !0 }, { text: "grid.filterIsFalse", operator: !1 } ], I = { text: !1, numeric: !1, date: !1, boolean: !0 }, v = (t, i, e, r = !0) => { const o = O(e.operators); let a = e.operator; switch (e.filterType) { case "numeric": case "date": (!a || s(a)) && (a = o), r && t === null && a === o && (a = ""); break; case "text": (!a || s(a)) && (a = o), r && !t && a === o && (a = ""); break; default: return; } e.onChange({ value: t, operator: a, syntheticEvent: i }); }, O = (t, i) => i ? t[i][0].operator : t[0].operator, F = (t) => t || "text", b = (t, i) => { const e = t.target.value; i({ value: e.operator, operator: e.operator === "" ? "" : x, syntheticEvent: t.syntheticEvent }); }, A = (t, i, e) => { let r = i; const o = t.target.value; t.target.state.opened && (s(o.operator) && (r = null), i === null && !s(o.operator) && (r = void 0), e({ value: r, operator: o.operator, syntheticEvent: t.syntheticEvent })); }, g = (t, i) => { const e = i || new u("en-US"); if (t.value) { const r = e.parseDate(t.value); r && (t.value = r); } t.filters && (t.filters = t.filters.map( (r) => { if (r.value) { const o = e.parseDate(r.value); o && (r.value = o); } return r; } )); }, L = (t, i) => { var r; let e = t; if (e && Object.keys(e).length === 0 && (e = null), e != null && e.filters && Array.isArray(e.filters)) { const o = i || { filters: [], logic: "and" }, a = o.filters.map((l) => l.field || l.filters[0].field), p = e.filters.every((l) => l.field === (e == null ? void 0 : e.filters[0]).field), n = p ? [ { filters: e.filters.map((l) => (g(l), l)), logic: e.logic } ] : e.filters.map((l) => { const d = l.filters ? l : { logic: t.logic, filters: [l] }; return g(d), d; }), f = p && a.includes(n[0].filters[0].field); if (f) { const l = o.filters[0]; l.filters && ((r = l.filters) == null || r.push(...n[0].filters), l.logic = t.logic); } e = { ...o, filters: f ? o.filters : [...o.filters, ...n] }; } return e; }; export { s as IsUnaryFilter, N as booleanFilterValues, b as cellBoolDropdownChange, v as cellInputChange, A as cellOperatorChange, L as combineSmartFilters, x as defaultBooleanOperator, I as defaultHideSecondFilter, q as filterLogicList, O as getDefaultOperator, F as getFilterType, h as operatorMap, E as operators, g as parseFilterDates };