From 1ed5b3930858c71bd06f1c5e1bf0d28dc6dcd6e5 Mon Sep 17 00:00:00 2001 From: Tsanie Date: Mon, 4 Mar 2024 15:17:31 +0800 Subject: [PATCH] optimize: change granularity is more fine-grained, only the changed cell elements are modified. --- lib/ui/grid/column.js | 11 ++++++++++- lib/ui/grid/grid.js | 35 +++++------------------------------ 2 files changed, 15 insertions(+), 31 deletions(-) diff --git a/lib/ui/grid/column.js b/lib/ui/grid/column.js index 51ac9d9..ee90b6f 100644 --- a/lib/ui/grid/column.js +++ b/lib/ui/grid/column.js @@ -133,7 +133,16 @@ export class GridColumn { } /** - * 单元格离开编辑元素时触发,需要由行包装对象的 `__editing` 来确定是否触发。 + * 单元格编辑状态发生改变时调用的方法 + * @method + * @name GridColumn.setEditing + * @param {HTMLElement} element - 单元格元素 + * @param {boolean} editing - 是否处于编辑状态 + * @virtual + */ + + /** + * 单元格离开编辑元素时调用的方法,需要由行包装对象的 `__editing` 来确定是否触发。 * @method * @name GridColumn.leaveEdit * @param {HTMLElement} element - 单元格元素 diff --git a/lib/ui/grid/grid.js b/lib/ui/grid/grid.js index 262d835..26fcd09 100644 --- a/lib/ui/grid/grid.js +++ b/lib/ui/grid/grid.js @@ -618,18 +618,6 @@ export class Grid { * @private */ startIndex: 0, - /** - * 旧选择索引数组 - * @type {number[]} - * @private - */ - oldSelectedIndexes: null, - /** - * 旧虚模式头部索引 - * @type {number} - * @private - */ - oldIndex: null, /** * 当前滚动上边距 * @type {number} @@ -2523,17 +2511,6 @@ export class Grid { _fillRows(rows, cols, widths) { const startIndex = this._var.startIndex; 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 readonly = this.readonly; rows.forEach((row, i) => { @@ -2611,12 +2588,7 @@ export class Grid { if (cell == null) { return; } - let virtualCell; - if (stateChanged) { - virtualRow.cells[j] = virtualCell = {}; - } else { - virtualCell = virtualRow.cells[j]; - } + const virtualCell = virtualRow.cells[j]; let val; if (col.text != null) { val = col.text; @@ -2693,7 +2665,10 @@ export class Grid { virtualCell.value = val; 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; if (readonly) { enabled = false;