remove dependency of jQuery plugins.

Grid.expandAll
add total field of exported data.
This commit is contained in:
2024-04-24 14:10:28 +08:00
parent 4e8be83625
commit f676ec76db
6 changed files with 400 additions and 183 deletions

View File

@ -367,6 +367,7 @@ let r = lang;
* @param {(boolean | string | number)} value - 修改后的值
* @param {(boolean | string | number)} oldValue - 修改前的值
* @param {any} [e] - 列修改事件传递过来的任意对象
* @param {GridExpandableObject} [expandableObject] - 列展开元素对象
* @this Grid
* @memberof GridColumnDefinition
*/
@ -610,6 +611,12 @@ export class Grid {
* @private
*/
currentSource: null,
/**
* 当前是否已全部展开
* @type {boolean}
* @private
*/
expanded: false,
/**
* 列可用性的关联字典
* @type {KeyMap<string | boolean>}
@ -2137,7 +2144,7 @@ export class Grid {
align: c.align,
visible: c.visible
})),
source: this.source.map(s => {
source: this.source?.map(s => {
const item = Object.create(null);
for (let c of this.columns) {
if (c.key == null) {
@ -2167,15 +2174,42 @@ export class Grid {
}
let val;
val = s[prop];
if (val != null) {
if (Object.prototype.hasOwnProperty.call(val, 'DisplayValue')) {
val = val.DisplayValue;
}
if (val != null && Object.prototype.hasOwnProperty.call(val, 'DisplayValue')) {
val = val.DisplayValue;
}
item[prop] = val;
}
return item;
}),
}) ?? [],
total: ((total) => {
if (total == null) {
return null;
}
const item = Object.create(null);
for (let c of this.columns) {
if (c.key == null) {
continue;
}
let val = total[c.key];
if (val != null && Object.prototype.hasOwnProperty.call(val, 'DisplayValue') && val.Value === val.DisplayValue) {
val = val.DisplayValue;
}
val ??= '';
item[c.key] = val;
}
for (let prop of Object.keys(total)) {
if (Object.prototype.hasOwnProperty.call(item, prop)) {
continue;
}
let val;
val = total[prop];
if (val != null && Object.prototype.hasOwnProperty.call(val, 'DisplayValue')) {
val = val.DisplayValue;
}
item[prop] = val;
}
return item;
})(this.total),
rowHeight: this.rowHeight,
sortDirection: this.sortDirection,
sortKey: this.sortKey,
@ -2236,10 +2270,32 @@ export class Grid {
}
})
working = true;
worker.postMessage({ type: 'init', path: ScriptPath.replace(/ui\.min\.js$/, 'wasm_flate_bg.wasm') });
worker.postMessage({ type: 'init', path: ScriptPath });
});
}
/**
* 展开/收折所有行
* @param {boolean} [expanded] - 是否展开,传 null 则切换展开状态
* @returns {boolean} 展开状态
*/
expandAll(expanded) {
if (this._var.currentSource == null) {
return;
}
if (expanded == null) {
expanded = !this._var.expanded;
} else {
expanded = expanded !== false;
}
this._var.expanded = expanded;
for (let vals of this._var.currentSource) {
vals.__expanded = expanded;
}
this.refresh();
return expanded;
}
/**
* @private
* @callback PrivateGridComparerCallback
@ -3892,10 +3948,11 @@ export class Grid {
}
const enabled = isFunction ? col.enabled(item) : isString ? item[col.enabled] : col.enabled;
if (enabled !== false) {
const old = item[key];
item[key] = flag;
row.__changed = true;
if (typeof col.onChanged === 'function') {
col.onChanged.call(this, item, flag);
col.onChanged.call(this, item, flag, old, void 0, row.__expandable_object);
}
}
}
@ -4209,7 +4266,7 @@ export class Grid {
});
vals.__changed = true;
if (typeof col.onChanged === 'function') {
col.onChanged.call(this, item, v, oldValue, e);
col.onChanged.call(this, item, v, oldValue, e, vals.__expandable_object);
}
}
}