ant-design-vue 2.0 a-table 中实现特殊行样式,选中样式,鼠标悬浮样式不一样

第一个是带选择框的a-table 使用如下方式实现:

rowClassName 属性可以传入自定义class

javascript 复制代码
 <a-table
            ref="table"
            size="middle"
            bordered
            :scroll="scroll"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeys,onChange: onSelectChange  }"
            :rowClassName="rowClassName"
          ></a-table>

这个rowClassName放在method属性中实现返回,代码如下:

javascript 复制代码
    rowClassName(record) {
      if (record.status === 2 || record.status === 5) { //销户或者后面的拉黑
        return 'highlight-row'
      } else if (record.status === 4 || record.status === 3) { //报停或者未开户
        return 'warning-row'
      }
      return ''
    },

然后less样式中如下进行调整
注意一定要deep穿透

css 复制代码
/deep/ .highlight-row {
  background-color: lightcoral !important;
  //实现悬浮样式修改
  &.ant-table-row-hover > td,
  .ant-table-tbody > tr.ant-table-row-hover > td,
  .ant-table-thead > tr:hover > td,
  .ant-table-tbody > tr:hover > td {
    background: #e41d1d !important;
  }
  // 实现选中样式修改
  &.ant-table-row-selected td {
    background: lightcoral !important;
  }
}

/deep/ .warning-row {
  background: yellow !important;
  &.ant-table-row-hover > td,
  .ant-table-tbody > tr.ant-table-row-hover > td,
  .ant-table-thead > tr:hover > td,
  .ant-table-tbody > tr:hover > td {
    background: #e3e31d !important;
  }
  &.ant-table-row-selected td {
    background: #f3f3aa !important;
  }
}

第二种当table是一个可以展开的多级table的时候,控制台查看元素发现,悬浮没有.ant-table-row-hover的class出现就需要使用如下方式实现,悬浮样式调整:

注意一定要deep穿透

css 复制代码
/deep/ .highlight-row {
  background: lightcoral !important;
}

/deep/ tr.ant-table-row.highlight-row:hover > td{
  background: #e41d1d !important;
}
相关推荐
东东51621 分钟前
基于ssm的网上房屋中介管理系统vue
前端·javascript·vue.js
harrain1 小时前
什么!vue3.4开始,v-model不能用在prop上
前端·javascript·vue.js
阿蒙Amon6 小时前
TypeScript学习-第7章:泛型(Generic)
javascript·学习·typescript
睡美人的小仙女1277 小时前
Threejs加载环境贴图报错Bad File Format: bad initial token
开发语言·javascript·redis
fanruitian7 小时前
uniapp android开发 测试板本与发行版本
前端·javascript·uni-app
rayufo7 小时前
【工具】列出指定文件夹下所有的目录和文件
开发语言·前端·python
RANCE_atttackkk7 小时前
[Java]实现使用邮箱找回密码的功能
java·开发语言·前端·spring boot·intellij-idea·idea
摘星编程8 小时前
React Native + OpenHarmony:Timeline垂直时间轴
javascript·react native·react.js
2501_944525548 小时前
Flutter for OpenHarmony 个人理财管理App实战 - 支出分析页面
android·开发语言·前端·javascript·flutter
jin1233229 小时前
React Native鸿蒙跨平台完成剧本杀组队详情页面,可以复用桌游、团建、赛事等各类组队详情页开发
javascript·react native·react.js·ecmascript·harmonyos