feature: add col.filterAllowNull
This commit is contained in:
@ -212,6 +212,7 @@ let r = lang;
|
||||
* @property {GridItem} attrs.item - 行数据对象
|
||||
* @property {object} attrs.{returns} - 返回附加属性对象
|
||||
* @property {boolean} [allowFilter=false] - 是否允许进行列头过滤
|
||||
* @property {boolean} [filterAllowNull=false] - 是否区分 `null` 与空字符串
|
||||
* @property {(GridItem[] | GridColumnFilterSourceCallback)} [filterSource] - 自定义列过滤器的数据源,允许调用如下函数
|
||||
* @property {Grid} filterSource.{this} - 上下文为 Grid
|
||||
* @property {GridColumnDefinition} filterSource.col - 列定义对象
|
||||
@ -1109,8 +1110,9 @@ export class Grid {
|
||||
if (this._var.colAttrs.__filtered === true) {
|
||||
this._var.currentSource = list.filter(it => {
|
||||
for (let col of this.columns) {
|
||||
const nullValue = col.filterAllowNull ? null : '';
|
||||
if (Array.isArray(col.filterValues)) {
|
||||
const v = this._getItemProp(it.values, false, col);
|
||||
const v = this._getItemProp(it.values, false, col) ?? nullValue;
|
||||
if (col.filterValues.indexOf(v) < 0) {
|
||||
return false;
|
||||
}
|
||||
@ -2650,7 +2652,7 @@ export class Grid {
|
||||
for (let item of this._var.source) {
|
||||
let displayValue = this._getItemProp(item.values, false, col);
|
||||
if (displayValue == null) {
|
||||
displayValue = this.langs.null;
|
||||
displayValue = col.filterAllowNull ? this.langs.null : '';
|
||||
}
|
||||
if (!Object.hasOwnProperty.call(dict, displayValue)) {
|
||||
const val = this._getItemProp(item.values, true, col);
|
||||
@ -2662,22 +2664,23 @@ export class Grid {
|
||||
}
|
||||
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;
|
||||
// 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;
|
||||
});
|
||||
}
|
||||
array = array.map(i => {
|
||||
@ -2724,7 +2727,8 @@ export class Grid {
|
||||
if (GridColumnTypeEnum.isCheckbox(col.type)) {
|
||||
col.filterValues = array.map(a => a.Value);
|
||||
} else {
|
||||
col.filterValues = array.map(a => a.DisplayValue);
|
||||
const nullValue = col.filterAllowNull ? null : '';
|
||||
col.filterValues = array.map(a => a.Value == null ? nullValue : a.DisplayValue);
|
||||
}
|
||||
}
|
||||
this._var.colAttrs.__filtered = true;
|
||||
@ -2770,8 +2774,12 @@ export class Grid {
|
||||
content.style.top = `${rowHeight}px`;
|
||||
this._set(col.key, 'filterSource', array);
|
||||
const propKey = GridColumnTypeEnum.isCheckbox(col.type) ? 'Value' : 'DisplayValue';
|
||||
const nullValue = col.filterAllowNull ? null : '';
|
||||
for (let item of array) {
|
||||
const v = Object.prototype.hasOwnProperty.call(item, propKey) ? item[propKey] : item;
|
||||
let v = item.Value ?? nullValue;
|
||||
if (v != null) {
|
||||
v = Object.prototype.hasOwnProperty.call(item, propKey) ? item[propKey] : item;
|
||||
}
|
||||
item.__checked = !Array.isArray(col.filterValues) || col.filterValues.includes(v);
|
||||
}
|
||||
if (array.length > 12) {
|
||||
|
Reference in New Issue
Block a user