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;
}
相关推荐
极客密码5 小时前
感谢雷总!Mimo大模型价值¥659/月的 MAX 套餐,让我免费领到了!
前端·ai编程·claude
深念Y6 小时前
我明白为什么B站没法在浏览器开直播了——Windows Chrome推流踩坑全记录
前端·chrome·webrtc·浏览器·srs·直播·flv
zhangxingchao6 小时前
AI应用开发七:可以替代 RAG 的技术
前端·人工智能·后端
Sun@happy6 小时前
现代 Web 前端渗透——基础篇(1)
前端·web安全
希冀1237 小时前
【CSS学习第十一篇】
前端·css·学习
隔窗听雨眠7 小时前
doctype、charset、meta如何控制整个渲染流水线
java·服务器·前端
kyriewen7 小时前
写组件文档写到吐?我用AI自动生成Storybook,同事以后直接抄
前端·javascript·面试
excel7 小时前
🧠 Prisma 表名大写 vs SQL 导出小写问题深度解析(附踩坑与解决方案)
前端·后端
周淳APP7 小时前
【前端工程化原理通识:从源头到运行时的理论阐述】
前端·编译·打包·前端工程化
五点六六六8 小时前
你敢信这是非Native页面写出来的渐变效果吗🌝(底层原理解析
前端·javascript·面试