optimize: change granularity is more fine-grained, only the changed cell elements are modified.

This commit is contained in:
Chen Lily 2024-03-04 15:17:31 +08:00
parent 975d54fee1
commit 1ed5b39308
2 changed files with 15 additions and 31 deletions

View File

@ -133,7 +133,16 @@ export class GridColumn {
} }
/** /**
* 单元格离开编辑元素时触发需要由行包装对象的 `__editing` 来确定是否触发 * 单元格编辑状态发生改变时调用的方法
* @method
* @name GridColumn.setEditing
* @param {HTMLElement} element - 单元格元素
* @param {boolean} editing - 是否处于编辑状态
* @virtual
*/
/**
* 单元格离开编辑元素时调用的方法需要由行包装对象的 `__editing` 来确定是否触发
* @method * @method
* @name GridColumn.leaveEdit * @name GridColumn.leaveEdit
* @param {HTMLElement} element - 单元格元素 * @param {HTMLElement} element - 单元格元素

View File

@ -618,18 +618,6 @@ export class Grid {
* @private * @private
*/ */
startIndex: 0, startIndex: 0,
/**
* 旧选择索引数组
* @type {number[]}
* @private
*/
oldSelectedIndexes: null,
/**
* 旧虚模式头部索引
* @type {number}
* @private
*/
oldIndex: null,
/** /**
* 当前滚动上边距 * 当前滚动上边距
* @type {number} * @type {number}
@ -2523,17 +2511,6 @@ export class Grid {
_fillRows(rows, cols, widths) { _fillRows(rows, cols, widths) {
const startIndex = this._var.startIndex; const startIndex = this._var.startIndex;
const selectedIndexes = this._var.selectedIndexes; const selectedIndexes = this._var.selectedIndexes;
// const stateChanged =
// this._var.oldIndex !== startIndex ||
// selectedIndexes == null ||
// this._var.oldSelectedIndexes?.length !== selectedIndexes.length ||
// this._var.oldSelectedIndexes.find((s, i) => s !== selectedIndexes[i]) != null;
// if (stateChanged) {
// this._var.oldIndex = startIndex;
// if (selectedIndexes != null) {
// this._var.oldSelectedIndexes = selectedIndexes.slice();
// }
// }
const offset = this.expandable ? 1 : 0; const offset = this.expandable ? 1 : 0;
const readonly = this.readonly; const readonly = this.readonly;
rows.forEach((row, i) => { rows.forEach((row, i) => {
@ -2611,12 +2588,7 @@ export class Grid {
if (cell == null) { if (cell == null) {
return; return;
} }
let virtualCell; const virtualCell = virtualRow.cells[j];
if (stateChanged) {
virtualRow.cells[j] = virtualCell = {};
} else {
virtualCell = virtualRow.cells[j];
}
let val; let val;
if (col.text != null) { if (col.text != null) {
val = col.text; val = col.text;
@ -2693,7 +2665,10 @@ export class Grid {
virtualCell.value = val; virtualCell.value = val;
type.setValue(element, val, vals, col, this); type.setValue(element, val, vals, col, this);
} }
if (typeof type.setEnabled === 'function') { if (stateChanged && typeof type.setEditing === 'function') {
type.setEditing(element, virtualRow.editing);
}
if (virtualRow.editing && typeof type.setEnabled === 'function') {
let enabled; let enabled;
if (readonly) { if (readonly) {
enabled = false; enabled = false;