【方式一】:通过设置customRow达到目的,点击时遍历所有行设置为正常颜色,把当前行设置为特殊颜色(高亮色)

HTML:

<a-table
ref="table"
size="small"
rowKey="id"
bordered
:columns="physicalSurveyColumns"
:data-source="physicalSurveyData"
:pagination="pagination"
:customRow="customRow"
>
</a-table>

JS -> methods:

// 自定义行
customRow(record) {
return {
on: {
click: (e) => {
const oldList = document.querySelectorAll('.checked-td-of-add-table')
if (oldList) {
for (let j = ; j < oldList.length; j++) {
oldList[j].classList.remove('checked-td-of-add-table')
}
} const children = e.target.parentNode.children
for (let i = ; i < children.length; i++) {
children[i].classList.add('checked-td-of-add-table')
}
}
}
}
}

CSS:

/deep/ .checked-td-of-add-table {
background-color: rgba(24, 144, 255, 0.5);
}

【方式二】:通过设置customRow达到目的,点击时记录ID,每一行就会自动加载style的样式,这里可以使用条件来达到加载不同样式的目的,比如设置行背景色:'background-color': record.id === this.physicalSurveyCurrRowId ? '#FFFF99' : 'white'

HTML:

<a-table
ref="table"
size="small"
rowKey="id"
bordered
:columns="physicalSurveyColumns"
:data-source="physicalSurveyData"
:pagination="pagination"
:customRow="customRow"
>
</a-table>

JS -> methods:

// 自定义行
customRow(record, index) {
return {
// 自定义属性,也就是官方文档中的props,可通过条件来控制样式
style: {
// 字体颜色
'color': record.id === this.physicalSurveyCurrRowId ? 'orange' : 'rgba(0, 0, 0, 0.65)',
// 行背景色
'background-color': record.id === this.physicalSurveyCurrRowId ? '#FFFF99' : 'white'
// // 字体类型
// 'font-family': 'Microsoft YaHei',
// // 下划线
// 'text-decoration': 'underline',
// // 字体样式-斜体
// 'font-style': 'italic',
// // 字体样式-斜体
// 'font-weight': 'bolder'
},
on: {
// 鼠标单击行
click: event => {
// 记录当前点击的行标识
this.physicalSurveyCurrRowId = record.id
}
}
}
}

【方式三】:与方式一类似,只是代码实现方式不同,通过设置customRow达到目的,点击时遍历所有行设置为正常颜色,把当前行设置为特殊颜色(高亮色)

HTML:

<a-table
ref="table"
size="small"
rowKey="id"
bordered
:columns="physicalSurveyColumns"
:data-source="physicalSurveyData"
:pagination="pagination"
:customRow="customRow"
>
</a-table>

JS -> methods:

// 自定义行
customRow(record, index) {
return {
on: {
// 鼠标单击行
click: event => {
event.currentTarget.parentNode.querySelectorAll('tr').forEach(item => {
item.style.background = 'white'
})
event.currentTarget.style.background = 'green'
}
}
}
}

【方式四】:通过设置customRow与rowClassName达到目的,点击时记录ID,rowClass就会根据是否是点击时的ID来加载指定的样式

HTML:

<a-table
ref="table"
size="small"
rowKey="id"
bordered
:columns="physicalSurveyColumns"
:data-source="physicalSurveyData"
:pagination="pagination"
:customRow="customRow"
:rowClassName="setRowClassName"
>
</a-table>

JS -> methods:

// 选中行
customRow(record, index) {
return {
on: {
click: () => {
this.physicalSurveyCurrRowId = record.id
}
}
}
},
setRowClassName(record) {
return record.id === this.physicalSurveyCurrRowId ? 'clickRowStyl' : ''
}

CSS:设置自定义行的悬浮样式

.ant-table-tbody {
.clickRowStyl:hover {
td {
background-color: #00b4ed;
}
}
}

都能达到目的,按需要选择。

antd-vue中table行高亮效果实现的更多相关文章

  1. JavaScript Table行定位效果

    作者:cloudgamer 时间: 2009-09-17 文档类型:原创 来自:蓝色理想 第 1 页 JavaScript Table行定位效果 [1] 第 2 页 JavaScript Table行 ...

  2. Vue中table表头合并的用法

    <div class="panel-container"> <div> <table class="table-head" wid ...

  3. Vue中table合并单元格用法

    <table> <tr> <th>地名</th> <th>结果</th> <th>人名</th> < ...

  4. vue中的路由高亮

  5. Vue中结合Flask与Node.JS的异步加载功能实现文章的分页效果

    你好!欢迎阅读我的博文,你可以跳转到我的个人博客网站,会有更好的排版效果和功能. 此外,本篇博文为本人Pushy原创,如需转载请注明出处:http://blog.pushy.site/posts/15 ...

  6. Vue中的动画效果

    Vue 在插入.更新或者移除 DOM 时,提供多种不同方式的应用过渡效果.包括以下工具: 在 CSS 过渡和动画中自动应用 class 可以配合使用第三方 CSS 动画库,如 Animate.css ...

  7. bootstrap中table页面做省市区级联效果(级联库见前面级联编辑)(非select下拉框)

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  8. 使用CodeMirror在浏览器中实现编辑器的代码高亮效果

    使用CodeMirror在浏览器中实现编辑器的代码高亮效果 在网站后台管理中希望能够对网站的样式表css与js文件以及模板html进行管理,在编辑的时候只是以普通文本展示又太普通,显得好难看,于是便在 ...

  9. VUE中实现iview的图标效果时遇到的一个问题

    [Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available ...

随机推荐

  1. activiti7 导出bpmn文件

    最近在学习springboot+activiti7整合,想做一个导出bpmn文件的功能,查了相关资料,最后没有实现.最后查看了一下代码 找到了方法 如下所示 @GetMapping("exp ...

  2. PHP xml_set_default_handler() 函数

    定义和用法 xml_set_default_handler() 函数为 XML 解析器建立默认的数据处理器.高佣联盟 www.cgewang.com 该函数规定在只要解析器在 XML 文件中找到数据时 ...

  3. P3239 [HNOI2015]亚瑟王 期望 dp

    LINK:亚瑟王 Saber!Excalibur! 比较难的期望dp. 可以发现如果暴力枚举所有的局面复杂度很高 . 转换的思路则是 期望的线性性. 求出每张牌的期望累加即可. 考虑每张牌的期望=这张 ...

  4. 面试必问的volatile关键字

    原文: 卡巴拉的树   https://juejin.im/post/5a2b53b7f265da432a7b821c 在Java相关的岗位面试中,很多面试官都喜欢考察面试者对Java并发的了解程度, ...

  5. Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile (default-testCompile) on project docker_springcloud_demo: Fatal error compiling: 无效的标记: -parameters -> [Help 1]

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile (def ...

  6. Android Studio局部管理器

    1.LinearLayout(线性布局) 该布局将其中的View子控件按照水平或者垂直方向排列.但是需要注意不管是水平还是竖直,对应的每一行或列都只能放一个控件. 线性布局两种排法: 从左到右:and ...

  7. eureka和feign的使用

    1 eureka和feign的简介(copy来的) eureka:Eureka是Netflix开发的服务发现组件,本身是一个基于REST的服务.Spring Cloud将它集成在其子项目spring- ...

  8. JVM系列之:再谈java中的safepoint

    目录 safepoint是什么 safepoint的例子 线程什么时候会进入safepoint safepoint是怎么工作的 总结 safepoint是什么 java程序里面有很多很多的java线程 ...

  9. 致敬平凡的程序员--《SOD框架“企业级”应用数据架构实战》自序

    “简单就是美” “平凡即是伟大” 上面两句话不知道是哪位名人说的,又或者是广大劳动人民总结的,反正我很小的时候就常常听到这两句话,这两句话也成了我的人生格言,而且事实上我也是一个生活过得比较简单的平凡 ...

  10. C#LeetCode刷题之#532-数组中的K-diff数对(K-diff Pairs in an Array)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3716 访问. 给定一个整数数组和一个整数 k, 你需要在数组里找 ...