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)

  },
相关推荐
Penge6665 小时前
《Go 后端开发者学 TypeScript:typescript 类型断言》
javascript
Penge6665 小时前
《Go 后端开发者学 TypeScript:Symbol》
javascript
三*一7 小时前
Mapbox‑GL JS 多边形折点编辑工具:实现原理、功能拆解与踩坑总结
开发语言·javascript·ecmascript
FungLeo8 小时前
成为全栈·基础补充·Node.js 运行时:事件循环与异步
javascript·node.js·事件循环·后端开发·异步编程·成为全栈
Penge6668 小时前
《Go 后端开发者学 TypeScript:类型别名》
javascript
Penge66616 小时前
《Go 后端开发者学 TypeScript:数组和元组》
javascript
Penge66617 小时前
《Go 后端开发者学 TypeScript:export关键字大全》
javascript
Penge66617 小时前
《Go 后端开发者学 TypeScript:从零理解 async、await 与 Promise》
javascript
Penge66617 小时前
typescript 中const用法
javascript
程序员大阳1 天前
HTML+CSS+JS对话式实战(3)-活动管理页实现查询、新增、删除API后端接口
javascript·css·html·实战·删除·查询·新增