antd-vue中table行高亮效果实现
【方式一】:通过设置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行高亮效果实现的更多相关文章
- JavaScript Table行定位效果
作者:cloudgamer 时间: 2009-09-17 文档类型:原创 来自:蓝色理想 第 1 页 JavaScript Table行定位效果 [1] 第 2 页 JavaScript Table行 ...
- Vue中table表头合并的用法
<div class="panel-container"> <div> <table class="table-head" wid ...
- Vue中table合并单元格用法
<table> <tr> <th>地名</th> <th>结果</th> <th>人名</th> < ...
- vue中的路由高亮
- Vue中结合Flask与Node.JS的异步加载功能实现文章的分页效果
你好!欢迎阅读我的博文,你可以跳转到我的个人博客网站,会有更好的排版效果和功能. 此外,本篇博文为本人Pushy原创,如需转载请注明出处:http://blog.pushy.site/posts/15 ...
- Vue中的动画效果
Vue 在插入.更新或者移除 DOM 时,提供多种不同方式的应用过渡效果.包括以下工具: 在 CSS 过渡和动画中自动应用 class 可以配合使用第三方 CSS 动画库,如 Animate.css ...
- bootstrap中table页面做省市区级联效果(级联库见前面级联编辑)(非select下拉框)
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- 使用CodeMirror在浏览器中实现编辑器的代码高亮效果
使用CodeMirror在浏览器中实现编辑器的代码高亮效果 在网站后台管理中希望能够对网站的样式表css与js文件以及模板html进行管理,在编辑的时候只是以普通文本展示又太普通,显得好难看,于是便在 ...
- VUE中实现iview的图标效果时遇到的一个问题
[Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available ...
随机推荐
- 记一次使用commit提交大文件无法推送到远程库解决问题过程及git rebase使用
记一次使用commit提交大文件无法推送到远程库解决问题过程及git rebase使用 目录 大文件无法push到远程仓库 问题 commit的大文件无法push到远程库解决办法 git filter ...
- Python 字典(Dictionary) items()方法
描述 Python 字典(Dictionary) items() 函数以列表返回可遍历的(键, 值) 元组数组.高佣联盟 www.cgewang.com 语法 items()方法语法: dict.it ...
- PHP time_nanosleep() 函数
实例 延迟执行当前脚本 3,5 秒: <?phpif (time_nanosleep(3,500000000) === true){高佣联盟 www.cgewang.comecho " ...
- ABP使用Nginx代理导致租户ID(Abp.TenantId)丢失
描述:ABP使用Nginx代理导致租户ID(Abp.TenantId)丢失,自定义header无效无法传递,导致租户选择认证失败.原因是因为 Nginx 过滤是“.”这符号. 解决: 1,先从代码人手 ...
- 简单的vector--- 2
如何重载operator[] 及其相关细节 如何使用 const_cast<>( ) 和 static_cast<>( ) 模板类 如何内部声明,外部定义友元函数 使用 ...
- SSH全注解-annotation详细配置
web.xml的配置: <!--Spring的装载器 --> <listener> <listener-class> org.springframework.web ...
- SEO(Search Engine Optimization)优化
SEO(Search Engine Optimization)汉议为搜索引擎优化,是一种利用搜索引擎的规则提高网站在有关搜索引擎内自然排名的方式. SEO的目的是对网站进行深度的优化,从而帮助网站获取 ...
- vue实现自定义表格列
在我们开发PC端的项目使用表单时,尤其是crm系统,应该经常会遇到这样的需求, 用户需要根据设置来自定义显示列. 查了element的官方文档, 并没有此类组件, 所以手动封装了一个简单的组件, 希望 ...
- 2018-04-19:innodb和myisam区别
福哥答案2020-04-19:
- C#开发笔记之03-为什么选择IsNotXXX方法而不是IsXXX方法?
C#开发笔记概述 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/959 访问. 为什么有时候要选择IsNotXXX方法而 ...