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;
}
相关推荐
shmily麻瓜小菜鸡1 小时前
JS/TS 易踩坑知识点 — 模块化与工程化类
开发语言·javascript·ecmascript
萧鼎1 小时前
Python 高性能Web框架神器 FastAPI:自动生成API文、基于Pydant、异步请求处理全搞定
前端·python·fastapi
IT_陈寒2 小时前
Redis误用keys命令把生产环境搞崩了,血的教训
前端·人工智能·后端
计算机魔术师2 小时前
5000亿估值冲刺科创板,DeepSeek 为何急着上市?
前端
我血条子呢2 小时前
前端解析word方案
前端·word
kyriewen3 小时前
我用 AI 写完一个需求后才发现,最难的不是 prompt,而是验收
前端·程序员·ai编程
申行3 小时前
Vue 3 + DYMO Connect Framework 实战:从标签模板到打印服务的完整实现
前端
两只羊ovo3 小时前
Vue 3 + DeepSeek 流式输出实战:从“干等”到“打字机”体验
前端·vue.js
Yeyu3 小时前
车载多 App 同屏渲染(二):SurfaceControlViewHost 跨进程
前端
樊小肆3 小时前
离谱,每轮请求 25% 的 token,竟在重发模型想完就扔的内心独白
前端·人工智能·agent