Skip to content

Commit

Permalink
Merge pull request #1172 from VisActor/1166-feature-contextmenuitems-col
Browse files Browse the repository at this point in the history
1166 feature contextmenuitems col
  • Loading branch information
fangsmile authored Feb 29, 2024
2 parents d39831e + c62bc85 commit 6bc126a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vtable",
"comment": "fix-contextMenuItems-add-col-param",
"type": "none"
}
],
"packageName": "@visactor/vtable"
}
2 changes: 1 addition & 1 deletion packages/react-vtable/src/components/component/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type MenuProps = {
/** 内置下拉菜单的全局设置项 目前只针对基本表格有效 会对每个表头单元格开启默认的下拉菜单功能。代替原来的option.dropDownMenu*/
defaultHeaderMenuItems?: TYPES.MenuListItem[];
/** 右键菜单。代替原来的option.contextmenu */
contextMenuItems?: TYPES.MenuListItem[] | ((field: string, row: number) => TYPES.MenuListItem[]);
contextMenuItems?: TYPES.MenuListItem[] | ((field: string, row: number, col: number) => TYPES.MenuListItem[]);
/** 设置选中状态的菜单。代替原来的option.dropDownMenuHighlight */
dropDownMenuHighlight?: TYPES.DropDownMenuHighlightInfo[];
} & BaseComponentProps;
Expand Down
4 changes: 2 additions & 2 deletions packages/vtable/examples/style/border.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ export function createTable() {
menu: {
renderMode: 'html',
defaultHeaderMenuItems: ['升序排序', '降序排序', '冻结列'],
contextMenuItems: (field: string, row: number) => {
console.log(field, row);
contextMenuItems: (field: string, row: number, col: number) => {
console.log(field, row, col);
return [
{ text: '复制表头', menuKey: '复制表头$1' },
{ text: '复制单元格', menuKey: '复制单元格$1' }
Expand Down
2 changes: 1 addition & 1 deletion packages/vtable/src/components/menu/dom/MenuHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class MenuHandler {
const abstractPos = table._getMouseAbstractPoint(e.event, false);
let menu = null;
if (abstractPos.inTable && typeof table.internalProps.menu?.contextMenuItems === 'function') {
menu = table.internalProps.menu.contextMenuItems(table.getHeaderField(e.col, e.row) as string, e.row);
menu = table.internalProps.menu.contextMenuItems(table.getHeaderField(e.col, e.row) as string, e.row, e.col);
} else if (abstractPos.inTable && Array.isArray(table.internalProps.menu?.contextMenuItems)) {
menu = table.internalProps.menu?.contextMenuItems;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vtable/src/scenegraph/component/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export class MenuHandler {
const { field } = this._table.isHeader(col, row)
? this._table.getHeaderDefine(col, row)
: this._table.getBodyColumnDefine(col, row);
menuInfo = contextmenu(field, row);
menuInfo = contextmenu(field, row, col);
}
return {
menuInfo,
Expand Down
4 changes: 2 additions & 2 deletions packages/vtable/src/ts-types/base-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export interface IBaseTableProtected {
/** 内置下拉菜单的全局设置项 目前只针对基本表格有效 会对每个表头单元格开启默认的下拉菜单功能。代替原来的option.dropDownMenu*/
defaultHeaderMenuItems?: MenuListItem[];
/** 右键菜单。代替原来的option.contextmenu */
contextMenuItems?: MenuListItem[] | ((field: FieldDef, row: number) => MenuListItem[]);
contextMenuItems?: MenuListItem[] | ((field: FieldDef, row: number, col: number) => MenuListItem[]);
/** 设置选中状态的菜单。代替原来的option.dropDownMenuHighlight */
dropDownMenuHighlight?: DropDownMenuHighlightInfo[];
};
Expand Down Expand Up @@ -301,7 +301,7 @@ export interface BaseTableConstructorOptions {
/** 内置下拉菜单的全局设置项 目前只针对基本表格有效 会对每个表头单元格开启默认的下拉菜单功能。代替原来的option.dropDownMenu*/
defaultHeaderMenuItems?: MenuListItem[];
/** 右键菜单。代替原来的option.contextmenu */
contextMenuItems?: MenuListItem[] | ((field: string, row: number) => MenuListItem[]);
contextMenuItems?: MenuListItem[] | ((field: string, row: number, col: number) => MenuListItem[]);
/** 设置选中状态的菜单。代替原来的option.dropDownMenuHighlight */
dropDownMenuHighlight?: DropDownMenuHighlightInfo[];
};
Expand Down

0 comments on commit 6bc126a

Please sign in to comment.