element-ui 表格获取单元格行和列的索引

<el-table :data="tableData" max-height="260" :span-method="merge" @cell-click="cellClick"
                :cell-class-name='getCellIndex' :cell-style="setCellStyle">
                <el-table-column fixed prop="name" width="70">

 通过:cell-class-name='getCellIndex'先把索引绑定到row下,点击实获取索引

cellClick: function (row, column, cell, event) {
  // console.log(row, column, cell, event);
  // var index = $(cell).index();
  this.forecastTime = parseFloat(column.label);
  this.size = parseFloat(row.size);
  // console.log(index, this.forecastTime);
  this.rowIndex = row.index;
  this.columnIndex = column.index;
},
getCellIndex: function ({ row, column, rowIndex, columnIndex }) {
  row.index = rowIndex;
  column.index = columnIndex;
},
setCellStyle: function ({ row, column, rowIndex, columnIndex }) {
  if (rowIndex === this.rowIndex && columnIndex === this.columnIndex) {
    return { "background-color": "#009221" }
  }
},
发布了121 篇原创文章 · 获赞 13 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/Vansal/article/details/103165515
今日推荐