20260723225430
This commit is contained in:
1 parent
4d118a0037
commit
4f40ad9f11
2 files changed
+24
-9
No files matched your search
@@ -5,11 +5,13 @@ function resolveOption(option, row) {
|
||||
return typeof option === "function" ? option(row) : option;
|
||||
}
|
||||
|
||||
export function createEditableCellRenderer({ getRowKey, getActiveRowKey }) {
|
||||
export function createEditableCellRenderer({ getRowKey, getActiveRowKey, getActiveColKey }) {
|
||||
return function EditableCell({ row, col, cellValue }) {
|
||||
const editor = typeof col.editor === "string" ? { type: col.editor } : col.editor || {};
|
||||
const activeRowKey = getActiveRowKey();
|
||||
const isEditing = activeRowKey != null && String(getRowKey(row)) === String(activeRowKey);
|
||||
const activeColKey = getActiveColKey?.();
|
||||
const shouldFocus = isEditing && (activeColKey == null || col.dataIndex === activeColKey);
|
||||
|
||||
const update = (value) => {
|
||||
row[col.dataIndex] = value;
|
||||
@@ -41,13 +43,15 @@ export function createEditableCellRenderer({ getRowKey, getActiveRowKey }) {
|
||||
size: "small",
|
||||
style: { width: "100%" },
|
||||
onClick: (event) => event.stopPropagation(),
|
||||
// 编辑态首次渲染自动聚焦
|
||||
ref: (instance) => {
|
||||
if (instance) {
|
||||
const target = instance.focus ? instance : instance.$el;
|
||||
target?.focus?.();
|
||||
}
|
||||
},
|
||||
// 仅被点击的列首次渲染时自动聚焦
|
||||
ref: shouldFocus
|
||||
? (instance) => {
|
||||
if (instance) {
|
||||
const target = instance.focus ? instance : instance.$el;
|
||||
target?.focus?.();
|
||||
}
|
||||
}
|
||||
: undefined,
|
||||
};
|
||||
|
||||
if (editor.type === "number") {
|
||||
|
||||
Reference in new issue
Block a user