diff --git a/common/changes/@visactor/vtable/760-bug-dropdown_menu_click_2023-12-19-03-39.json b/common/changes/@visactor/vtable/760-bug-dropdown_menu_click_2023-12-19-03-39.json new file mode 100644 index 000000000..d43ae8c73 --- /dev/null +++ b/common/changes/@visactor/vtable/760-bug-dropdown_menu_click_2023-12-19-03-39.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "fix: dropdown_menu_click trigger #760\n\n", + "type": "none", + "packageName": "@visactor/vtable" + } + ], + "packageName": "@visactor/vtable", + "email": "892739385@qq.com" +} \ No newline at end of file diff --git a/common/changes/@visactor/vtable/760-bug-dropdown_menu_click_2023-12-19-04-02.json b/common/changes/@visactor/vtable/760-bug-dropdown_menu_click_2023-12-19-04-02.json new file mode 100644 index 000000000..909832cbe --- /dev/null +++ b/common/changes/@visactor/vtable/760-bug-dropdown_menu_click_2023-12-19-04-02.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "fix: dblclick occur error #758\n\n", + "type": "none", + "packageName": "@visactor/vtable" + } + ], + "packageName": "@visactor/vtable", + "email": "892739385@qq.com" +} \ No newline at end of file diff --git a/packages/vtable/examples/interactive/menu.ts b/packages/vtable/examples/interactive/menu.ts index 9f3de4506..5f6b57fc3 100644 --- a/packages/vtable/examples/interactive/menu.ts +++ b/packages/vtable/examples/interactive/menu.ts @@ -181,7 +181,10 @@ export function createTable() { // instance.showDropDownMenu(col, row, { // content: ['a', 'b'] // }); - + instance.on('dropdown_menu_click', args => { + console.log('dropdown_menu_click', args); + instance.setDropDownMenuHighlight([args]); + }); // 只为了方便控制太调试用,不要拷贝 window.tableInstance = instance; } diff --git a/packages/vtable/src/core/BaseTable.ts b/packages/vtable/src/core/BaseTable.ts index 2827479fc..5dd0ddd64 100644 --- a/packages/vtable/src/core/BaseTable.ts +++ b/packages/vtable/src/core/BaseTable.ts @@ -2784,21 +2784,24 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI { } /** 获取单元格的基本信息 目前主要组织单元格信息给事件传递给用户的参数使用 */ getCellInfo(col: number, row: number): Omit { - const colDef = this.isHeader(col, row) ? this.getHeaderDefine(col, row) : this.getBodyColumnDefine(col, row); - return { - col, - row, - field: this.getHeaderField(col, row), - cellHeaderPaths: this.internalProps.layoutMap.getCellHeaderPaths(col, row), - title: colDef?.title, - cellType: colDef?.cellType ? (typeof colDef.cellType === 'string' ? colDef.cellType : 'progressbar') : 'text', - originData: this.getCellOriginRecord(col, row), - cellRange: this.getCellRangeRelativeRect({ col, row }), - value: this.getCellValue(col, row), - dataValue: this.getCellOriginValue(col, row), - cellLocation: this.getCellLocation(col, row), - scaleRatio: this.canvas.getBoundingClientRect().width / this.canvas.offsetWidth - }; + if (col >= 0 && row >= 0) { + const colDef = this.isHeader(col, row) ? this.getHeaderDefine(col, row) : this.getBodyColumnDefine(col, row); + return { + col, + row, + field: this.getHeaderField(col, row), + cellHeaderPaths: this.internalProps.layoutMap.getCellHeaderPaths(col, row), + title: colDef?.title, + cellType: colDef?.cellType ? (typeof colDef.cellType === 'string' ? colDef.cellType : 'progressbar') : 'text', + originData: this.getCellOriginRecord(col, row), + cellRange: this.getCellRangeRelativeRect({ col, row }), + value: this.getCellValue(col, row), + dataValue: this.getCellOriginValue(col, row), + cellLocation: this.getCellLocation(col, row), + scaleRatio: this.canvas.getBoundingClientRect().width / this.canvas.offsetWidth + }; + } + return undefined; } /** @private */ _hasField(field: FieldDef, col: number, row: number): boolean { diff --git a/packages/vtable/src/event/listener/table-group.ts b/packages/vtable/src/event/listener/table-group.ts index 69c01b7f1..02f3dbe49 100644 --- a/packages/vtable/src/event/listener/table-group.ts +++ b/packages/vtable/src/event/listener/table-group.ts @@ -285,7 +285,9 @@ export function bindTableGroupListener(eventManager: EventManager) { table.scenegraph.tableGroup.addEventListener('pointerupoutside', (e: FederatedPointerEvent) => { const eventArgsSet: SceneEvent = getCellEventArgsSet(e); if (stateManager.menu.isShow && (eventArgsSet.eventArgs?.target as any) !== stateManager.residentHoverIcon?.icon) { - stateManager.hideMenu(); + setTimeout(() => { + stateManager.menu.isShow && stateManager.hideMenu(); + }, 0); } // 同pointerup中的逻辑 if (stateManager.isResizeCol()) { @@ -721,13 +723,20 @@ function endResizeCol(table: BaseTableAPI) { function dblclickHandler(e: FederatedPointerEvent, table: BaseTableAPI) { const eventArgsSet: SceneEvent = getCellEventArgsSet(e); - const bounds = eventArgsSet.eventArgs.targetCell.globalAABBBounds; - const { col, row } = eventArgsSet.eventArgs; + let col = -1; + let row = -1; + if (eventArgsSet.eventArgs) { + col = eventArgsSet.eventArgs.col; + row = eventArgsSet.eventArgs.row; + } const value = table.getCellValue(col, row); - table.internalProps.focusControl.setFocusRect( - new Rect(bounds.x1 + table.scrollLeft, bounds.y1 + table.scrollTop, bounds.x2 - bounds.x1, bounds.y2 - bounds.y1), - value - ); + + const bounds = eventArgsSet.eventArgs?.targetCell?.globalAABBBounds; + bounds && + table.internalProps.focusControl.setFocusRect( + new Rect(bounds.x1 + table.scrollLeft, bounds.y1 + table.scrollTop, bounds.x2 - bounds.x1, bounds.y2 - bounds.y1), + value + ); if ((table as any).hasListeners(TABLE_EVENT_TYPE.DBLCLICK_CELL)) { const cellInfo = table.getCellInfo(col, row); let icon;