ant design of VUE 表格头点击双击事件

一开始我以为也是像customRow 一样是写在a-table里面就行了,于是开始上手操作,发现没有一点一效果经过一阵子研究原来customHeaderCell是写在columns里面的

话不多说上代码

const columns = [
  {
    title: 'xxx',
    dataIndex: 'time',
    key: 'time',
    align: "center",
    customHeaderCell:columns=>{
        return{
        on:{
            click:()=>{
                console.log('点击事件',columns)
            },
            dblclick:()=>{
               console.log('双击事件',columns)
            }
        }
      }
    }
  },
];

这个时候就在有此函数的表头上就已经有了相应的事件了


当然了,作为表格肯定不能只有一个表头,肯定不能每个上面都写这样一个函数,下面我们就进行函数提取

function customHeaderCell(params) {
  return{
    on:{
      click:()=>{
        console.log('函数封装点击事件',params,1)
      },
      dblclick:()=>{
        console.log('函数封装双击击事件',params,2)
      }
    }
  }
}

const columns = [
  {
    title: 'xxx',
    dataIndex: 'time',
    key: 'time',
    align: "center"
  },
  {
    title: 'xxx',
    dataIndex: 'x1',
    key: 'x1',
    align: "center",
    customHeaderCell:customHeaderCell
  },
  {
    title: 'xxx',
    dataIndex: 'x2',
    key: 'x2',
    align: "center",
    customHeaderCell:customHeaderCell
  },
  {
    title: 'xxx',
    key: 'x3',
    dataIndex: '3',
    scopedSlots: { customRender: 'x3' },
    align: "center",
    customHeaderCell:customHeaderCell
  }
];

这样一个简单的函数提取就搞定了

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Ant Design of Vue 是一套基于 Vue.js 的 UI 组件库,其中包含了丰富的组件,包括表格组件。下面是一个带分页和多选功能的 Ant Design of Vue 表格示例: ```html <template> <a-table :columns="columns" :data-source="dataSource" :pagination="pagination" row-selection="rowSelection" @change="handleTableChange"> </a-table> </template> <script> export default { data() { return { columns: [ { title: '姓名', dataIndex: 'name' }, { title: '年龄', dataIndex: 'age' }, { title: '地址', dataIndex: 'address' } ], dataSource: [], // 表格数据 pagination: { // 分页配置 current: 1, // 当前页码 pageSize: 10, // 每页显示条数 total: 0 // 数据总条数 }, rowSelection: { // 多选配置 selectedRowKeys: [], onChange: this.handleRowSelectionChange } } }, methods: { // 处理表格变化事件 handleTableChange(pagination) { this.pagination = pagination this.fetchData() }, // 处理多选变化事件 handleRowSelectionChange(selectedRowKeys) { this.rowSelection.selectedRowKeys = selectedRowKeys }, // 获取表格数据 fetchData() { // 发送异步请求获取数据 // ... // 设置表格数据和分页信息 this.dataSource = [] this.pagination.total = 100 } }, mounted() { // 初始化数据 this.fetchData() } } </script> ``` 在上面的代码中,`columns` 数组定义了表格的列信息,`dataSource` 数组存储了表格的数据,`pagination` 对象定义了分页信息,`rowSelection` 对象定义了多选配置。在 `a-table` 组件中,我们将这些配置传递给了组件,并设置了相应的事件回调函数。在 `handleTableChange` 方法中,我们处理了分页变化事件,在 `handleRowSelectionChange` 方法中,我们处理了多选变化事件。`fetchData` 方法用于获取表格数据,我们可以在其中发送异步请求获取数据,并设置表格数据和分页信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值