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;
}
相关推荐
wulijuan8886662 小时前
前端性能优化之图片webp
前端
一颗烂土豆2 小时前
ECharts 水球图不够炫?试试 RayChart 的创意可视化玩法
前端·vue.js·数据可视化
如果你好2 小时前
TypeScript 接口(interface)完全指南:语法、特性与实战技巧
vue.js·typescript
天才熊猫君2 小时前
Vue 3 命令式弹窗组件
前端
NEXT062 小时前
CSS基础-标准盒模型与怪异盒模型
前端·css
DaMu2 小时前
Dreamcore3D ARPG IDE “手搓”游戏引擎,轻量级实时3D创作工具,丝滑操作,即使小白也能轻松愉快的创作出属于你自己的游戏世界!
前端·架构·three.js
代码猎人2 小时前
什么是尾调用,使用尾调用有什么好处?
前端
AI_56782 小时前
Webpack从“配置到提速”,4步解决“打包慢、体积大”问题
前端·javascript·vue.js
pinkQQx2 小时前
手把手搭建前端跨平台服务(IPlatform + iOS / Android / Web)
前端·javascript