From 03e3b4a70f4919b2fb3bf9e22e56b04b8190af23 Mon Sep 17 00:00:00 2001 From: Tsanie Lily Date: Wed, 27 Mar 2024 13:36:31 +0800 Subject: [PATCH] add: column.filterAsValue fix: case-sensitive order of Array value --- lib/ui/grid/grid.js | 56 ++++++++++++++++++++++++++++----------------- package-lock.json | 6 ++--- 2 files changed, 38 insertions(+), 24 deletions(-) diff --git a/lib/ui/grid/grid.js b/lib/ui/grid/grid.js index b78b278..7cc52a6 100644 --- a/lib/ui/grid/grid.js +++ b/lib/ui/grid/grid.js @@ -255,6 +255,7 @@ let r = lang; * @property {any[]} [filterValues] - 过滤值的数组 * @property {boolean} [filterAllowNull=false] - 是否区分 `null` 与空字符串 * @property {(ValueItem[] | GridColumnFilterSourceCallback)} [filterSource] - 自定义列过滤器的数据源,支持调用函数返回数据源 + * @property {boolean} [filterAsValue=false] - 列头过滤强制使用 `Value` 字段 * @property {GridItemSortCallback} [sortFilter] - 自定义列排序函数 * @property {DropdownOptions} [dropOptions] - 列为下拉列表类型时以该值设置下拉框的参数 * @property {(GridSourceItem[] | Promise | GridDropdownSourceCallback)} [source] - 列为下拉列表类型时以该值设置下拉列表数据源,支持返回异步对象,也支持调用函数返回 @@ -2265,9 +2266,17 @@ export class Grid { b = 0; } else if (a != null && b == null) { return direction; - } else if (typeof a === 'string' && typeof b === 'string') { - a = a.toLowerCase(); - b = b.toLowerCase(); + } else { + if (Array.isArray(a)) { + a = a.join(', '); + } + if (Array.isArray(b)) { + b = b.join(', '); + } + if (typeof a === 'string' && typeof b === 'string') { + a = a.toLowerCase(); + b = b.toLowerCase(); + } } return a === b ? 0 : (a > b ? 1 : -1) * direction; }; @@ -3489,25 +3498,30 @@ export class Grid { }; } } + const filterAsValue = col.filterAsValue; array = Object.values(dict) - .sort((a, b) => { - // if (a == null && b == null) { - // return 0; - // } - // if (a == null && b != null) { - // return -1; - // } - // if (a != null && b == null) { - // return 1; - // } - // if (Object.prototype.hasOwnProperty.call(a, 'Value')) { - // a = a.Value; - // } - // if (Object.prototype.hasOwnProperty.call(b, 'Value')) { - // b = b.Value; - // } - // return a > b ? 1 : a < b ? -1 : 0; - return a.Value > b.Value ? 1 : a.Value < b.Value ? -1 : 0; + .sort((itemA, itemB) => { + let a = itemA.Value; + let b = itemB.Value; + if (a instanceof Date || b instanceof Date) { + if (a == null) { + a = 0; + } else if (b == null) { + b = 0; + } + } else if (a != null && b == null) { + return 1; + } else { + if (!filterAsValue) { + a = itemA.DisplayValue; + b = itemB.DisplayValue; + } + if (typeof a === 'string' && typeof b === 'string') { + a = a.toLowerCase(); + b = b.toLowerCase(); + } + } + return a > b ? 1 : (a < b ? -1 : 0); }); } array = array.map(i => { diff --git a/package-lock.json b/package-lock.json index 760f2c0..44bf58a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2041,9 +2041,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.715", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.715.tgz", - "integrity": "sha512-XzWNH4ZSa9BwVUQSDorPWAUQ5WGuYz7zJUNpNif40zFCiCl20t8zgylmreNmn26h5kiyw2lg7RfTmeMBsDklqg==", + "version": "1.4.717", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.717.tgz", + "integrity": "sha512-6Fmg8QkkumNOwuZ/5mIbMU9WI3H2fmn5ajcVya64I5Yr5CcNmO7vcLt0Y7c96DCiMO5/9G+4sI2r6eEvdg1F7A==", "dev": true }, "node_modules/entities": {