element实现点击每列展开数据行

705 阅读1分钟

element实现点击每列展开数据行

element官网的有个Table 展开行功能,但是只能点击固定列展开,我想实现点击指定列都能展开对应数据,利用一些属性稍微改造了一下

表格代码片段
在这里插入图片描述
展开行代码片段
在这里插入图片描述
一些属性含义,官网都有解释
在这里插入图片描述
toggleRowExpansion(row) //主要这一句,切换某一行的展开状态

// :row-key='getRowKeys' // 设置Table行数据的 Key
      getRowKeys(row) {
        return row.PerID
      },
      //@expand-change="expandChange" //某行展开或者关闭的时候会触发事件
      expandChange(row, expandedRows) {
        let that = this
        console.log('qqqqq', row, expandedRows);
        //只展开一行
        if (expandedRows.length) { //说明展开了
          that.expands = []
          if (row) {
            that.expands.push(row.PerID) //只展开当前行id
          }
        } else { //说明收起了
          that.expands = []
        }
      },

      //@row-click="rowClick"  //某行被点击时触发事件
      rowClick(row, column, event) {
        let that = this
        // console.log(row, column, event)
        //row 点击这行的数据
        //column.property 点击列的标题
        if (column.property == 'kecheng') {   //如果点击不同列展开不同数据则用 column.property 判断即可
          that.unfoldsts = 1
          that.$refs.multipleTable.toggleRowExpansion(row) //切换某一行的展开状态
        }
      },

欢迎大家一起讨论,一起成长