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

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

javascript 复制代码
  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)

  },
相关推荐
whyweplay几秒前
Elpis:从Json Schema 到 页面
前端·javascript
大牧师34 分钟前
Nest.js 微服务入门教程
开发语言·javascript·后端·微服务·node.js·nest.js·nest
低代码布道师1 小时前
外包项目管理平台全栈实战课02搭建数据底座:Next.js + PostgreSQL + Prisma 7
开发语言·javascript·postgresql·全栈开发
志尊宝1 小时前
Vue3 零基础每日笔记(004):模板语法初识——插值表达式、v-bind、v-on 一次学会
javascript·vue.js·笔记
JeffongTan10 小时前
在LWC中镶嵌VF Page获取用户IP
前端·javascript·salesforce
不cong明的亚子12 小时前
web live多屏互动平台
javascript·经验分享·音视频
dsyyyyy110114 小时前
JS复习,难点,易错点总结
开发语言·javascript·ecmascript
默_笙14 小时前
🏝 Docker 就是"房地产开发":从施工图纸到小区物业的容器化指南
前端·javascript
kyriewen14 小时前
我手写了个极简版 React Router——才搞懂 v6 为什么砍了这么多 API
前端·javascript·程序员