elementUi中的el-table合计行添加点击事件

elementUi 文档中,合计行并没有点击事件,这里自己实现了合计行的点击事件。

  created() {
    this.propertyList = [
      { property: 'order', label: '序号' },
      { property: 'deptName', label: '单位名称' },
      { property: 'contentPublishQuantity', label: '文章数量' },
      { property: 'readQuantity', label: '浏览量' },
      { property: 'likeQuantity', label: '点赞量' },
      { property: 'collectionQuantity', label: '收藏量' },
    ]
  },
 mounted() {
    let that = this
    setTimeout(() => {
      const footerWrapper = this.$el.querySelector('.el-table__footer-wrapper');
      const cells = this.$el.querySelectorAll('.el-table__footer-wrapper td .cell');
      // 给文章数量和收藏量添加样式
      let clickIndex = [2,5]
      if (cells.length) {
        cells.forEach((cell, index) => {
          if (clickIndex.includes(index)) {
            cell.style.color = '#409EFF'
            cell.style.cursor = 'pointer'
          }
        })
      }
      // 在合计行添加点击事件
      footerWrapper.addEventListener('click', (event) => {
        // 检查点击事件是否发生在合计行的单元格上
        const targetCell = event.target.closest('.el-table__cell');
        if (targetCell) {
          // 获取点击的列索引
          const columnIndex = Array.from(targetCell.parentNode.children).indexOf(targetCell);
          if (columnIndex !== -1) {
            console.log('当前点击项:',that.propertyList[columnIndex])
          }
        }
      });
    }, 500)

  },
  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值