vue Element-ui 表格多选 修改选中行背景色

<el-table
  v-show="res"
  border
  ref="multipleTable"
  :data="projectList"
  tooltip-effect="dark"
  style="width: 100%"
  @selection-change="handleSelectionChange"
  @select="handleSelection"
  @row-click="clickRow"
  :row-class-name="tableRowClassName"
>
  <el-table-column type="selection" width="30"></el-table-column>
  <el-table-column label="ID" align="center" prop="id">
    <template slot-scope="scope">{{ scope.row.id }}</template>
  </el-table-column>
  <el-table-column label="项目名称" align="center" prop="name">
    <template slot-scope="scope">{{scope.row.name}}</template>
  </el-table-column>
  <el-table-column label="征收范围" align="center" prop="levy_scope">
    <template slot-scope="scope">{{scope.row.levy_scope}}</template>
  </el-table-column>
  <el-table-column label="拆迁公司" align="center" prop="actuator">
    <template slot-scope="scope">{{scope.row.actuator}}</template>
  </el-table-column>
</el-table>
.el-table >>> .warning-row {
  background-color: #f5f7fa;
}

点击选框 点击整行 都可以变色

handleSelectionChange(val) {
  this.multipleSelection = val;
  console.log("选择框发生变化", val);
},
handleSelection(val, row) {
  console.log(o.id, "什么row", o);

  // 表单绑定的数据
  this.projectList.forEach((item, i) => {
    if (item.id == row.id) {
      /* console.log(this.numbers.indexOf(i)) */
      if (this.numbers.indexOf(i) == -1) {
        this.numbers.push(i);
      } else {
        this.numbers.splice(this.numbers.indexOf(i), 1);
      }
    }
  });

},
// 点击整行选中
clickRow(row, event, column) {
  this.$refs.multipleTable.toggleRowSelection(row);

  this.projectList.forEach((r, i) => {
    if (r.id == row.id) {
      /* console.log(this.numbers.indexOf(i)) */
      if (this.numbers.indexOf(i) == -1) {
        this.numbers.push(i);
      } else {
        this.numbers.splice(this.numbers.indexOf(i), 1);
      }
    }
  });
  
},
// 选中背景色
tableRowClassName({ row, rowIndex }) {
  let color = "";
  this.numbers.forEach((r, i) => {
    if (rowIndex === r) {
      color = "warning-row";
    }
  });
  return color;
}



转自:https://www.jianshu.com/p/47aa76b1450e

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值