vxe-table 右键菜单设置

这篇博客介绍了如何在vxe-table中设置右键菜单功能。通过vue代码示例展示了点击右键后显示菜单项,并能响应选择,同时提到了表内容的默认数据设置和事件处理模块。

1、vxe-table中点击右键出现右键菜单项,可以选择右键菜单中的内容; vue 部分代码

<!--- 
-----注:关键点: 
------右键菜单项:menu-config="table.rightMenu" 
------点击右键中的菜单事件 @menu-click="menuClick" 
---> 
<vxe-table
     border
     ref="xTable"
     class="moz-style" 
     :menu-config="table.rightMenu"
     resizable 
     :columns="table.columns" 
     :data="table.dataSource" 
     @menu-click="menuClick" 
 > 
</vxe-table>

2、表内容默认数据设置部分;

/** ...其他内容略过... **/
data(){
       return { 
            table: {
               loading: true, 
               rightMenu: {
                    className: 'my-menus',
                    body: {
                        options: [
                            [
                                { code: 'addRowOne', name: '新增' },
                                { code: 'handleDelete', name: '删除' }, 
                            ]
                        ]
                    },
                    visibleMethod: this.visibleMethod
                }, 
               columns: [
                   {field: 'top_xh', title: '序号',align: 'center', dataIndex: 'top_xh'},
                   {field: 'work_content', title: '内容', width: '130px', editRender: {},  dataIndex: 'work_content'},
                   {field: 'complete_form', title: '形式', width: '130px', editRender: {}, dataIndex: 'complete_form'},
                   {field: 'plan_complete_date', title: '节点', editRender: {}, dataIndex: 'plan_complete_date'},
                   {field: 'person_in_charge',title: '日期',editRender: {},  dataIndex: 'person_in_charge'},
                   {field: 'complete_status',title: '是否完成',editRender: {},  dataIndex: 'complete_status'},
                   {field: 'remark',title: '备注', editRender: {}, slots: { edit: 'score_edit'}}, 
                   {field: 'action', title: '操作',  dataIndex: 'action',  align: "center", scopedSlots: {customRender: 'action'}}
               ], 
               columnsList: [], 
               data:[],
               dataSource: [],
           },
       }
   }, 

3、执行的事件模块部分

//点击右键时执行的事件
visibleMethod(){},
//菜单点击
menuClick(options) {
    if(options.menu.code == 'addRowOne') {
        this.addRowOne(options.row, options.column)
    }  
    if(options.menu.code == 'handleDelete') {
       this.handleDelete(options.row,  options.rowIndex, options.column)
    }  
 },
//新增事件
addRowOne(row, column){
    let one_row = {}
    this.table.dataSource.push(one_row)
},
//删除事件
handleDelete(row, rowIndex, column){
    let dataS = JSON.parse(JSON.stringify(this.table.dataSource)) 
    delete dataS[rowIndex] 
    this.table.dataSource = dataS
},

以上内容仅供参考!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值