This commit is contained in:
2024-01-25 14:56:31 +08:00
parent 07f87bfb9d
commit 9ab9edb44d
18 changed files with 594 additions and 186 deletions

View File

@ -133,6 +133,14 @@ export class Grid {
get element() { return this._var.el }
get changed() {
const source = this._var.source;
if (source == null) {
return false;
}
return source.filter(r => r.__changed).length > 0;
}
get source() { return this._var.source?.map(s => s.values) }
set source(list) {
if (this._var.el == null) {
@ -148,11 +156,32 @@ export class Grid {
setItem(index, item) {
if (this._var.source == null) {
return;
throw new Error('no source');
}
const it = this._var.source[index];
delete it.source;
it.values = item;
this.refresh();
}
addItem(item, index) {
if (this._var.source == null) {
throw new Error('no source');
}
if (index >= 0) {
this._var.source.splice(index, 0, { values: item });
} else {
this._var.source.push({ values: item });
}
this.reload();
}
removeItem(index) {
if (this._var.source == null) {
throw new Error('no source');
}
this._var.source.splice(index, 1);
this.reload();
}
_refreshSource(list) {
@ -344,7 +373,7 @@ export class Grid {
this._var.el.scrollTop = top;
}
resize(force) {
resize(force, keep) {
if (this._var.rendering || this._var.el == null) {
return;
}
@ -360,7 +389,7 @@ export class Grid {
const count = truncate((height - 1) / (this.rowHeight + 1)) + (RedumCount * 2) + 1;
if (force || count !== this._var.rowCount) {
this._var.rowCount = count;
this.reload(true);
this.reload(keep);
}
this._var.bodyClientWidth = body.clientWidth;
}
@ -760,11 +789,11 @@ export class Grid {
}
if (type.editing) {
val = type.getValue({ target: cell.children[0] }, col);
this._onRowChanged(null, startIndex + i, col, val, cell, true);
this._onRowChanged(null, i, col, val, cell, true);
}
}
element = selected ?
type.createEdit(e => this._onRowChanged(e, startIndex + i, col, type.getValue(e, col), cell), col, this._var.el, vals) :
type.createEdit(e => this._onRowChanged(e, i, col, type.getValue(e, col), cell), col, this._var.el, vals) :
type.create(col);
cell.replaceChildren(element);
} else {
@ -1179,7 +1208,7 @@ export class Grid {
const key = e.currentTarget.value.toLowerCase();
const items = key.length === 0 ? array : array.filter(i => {
const displayValue = i?.DisplayValue ?? i;
return String(displayValue ?? '').includes(key);
return String(displayValue ?? '').toLowerCase().includes(key);
});
this._fillFilterList(col, itemlist, items, itemall);
});
@ -1288,7 +1317,7 @@ export class Grid {
}
const content = list.querySelector('.filter-content');
content.replaceChildren();
this._doFillFilterList(content, array, list.querySelector('.filter-all>input'));
this._doFillFilterList(content, array, list.querySelector('.filter-all'));
content.style.top = `${top + rowHeight}px`;
}
}