antd-vue中table行高亮效果实现

摘要:
'orange':'rgba(0,0,0,0.65)',//行背景色'background-color':record.id===this.physicalSurveyCurrRowId?

【方式一】:通过设置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 = 0; j < oldList.length; j++) {
            oldList[j].classList.remove('checked-td-of-add-table')
          }
        }

        const children =e.target.parentNode.children
        for (let i = 0; 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行高亮效果实现》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇uni-app 实现安卓物理返回键返回,触发弹框提示是否退出zbar配置下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

NPOI 2.0导出word(docx格式)

大名鼎鼎的NPOI用来导出EXCEL的文章园子里面有很多,可是用来导出WORD文档的文章大都含糊不清,最近刚好完成一个导出WORD文档的需求,在此分享下。 NPOI里面认为word文档的最基本的结构是段落,代表这个段落的类就是XWPFParagraph,使用这个类可以设置段落里面的字体、大小、以及是否加粗等。 代表整个文档的的类XWPFDocument,是...

JS实现日程安排 日程安排插件

    代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EmpWeekPlan.aspx.cs" Inherits="Aepri.InfoDev.DPP.Web.PlanManage.EmpWeekPlan" %> <!DOCTYPE html>...

4、HTML和CSS进阶知识

HTML和CSS进阶知识 一、HTML中常用的块元素(block)和行内元素(inline)   常见的块元素(block):p、h1--h6、div、ul、ol、dl、hr   常见的行内元素(inline):b、i、em、strong、small、sub、sup、a、span、br、   在css中,可以通过display属性实现block元素和inl...

基于ElementUi封装table组件——包含表头工具栏、多级表头、合并行、分页

表格组件WTable.vue <template> <div class="wTable"> <!--头部工具栏 --> <div v-if="tools && tools.length>0 && tools[0].label"class...

Python 操作GridFS

importpymongo from pymongo importMongoClient from gridfs importGridFS classGFS(object): def __init__(self, file_db,file_table): self.file_db =file_db self.file...

td中内容自动换行

使用<table> 进行页面开发,会遇到字符串很长将table撑开变形的问题,在网上搜了一些,终于找到 一个比较好用的解决方法。贴出来,方便以后使用。在table标签中加入如下的style就行了。<table border="0" cellspacing="0" cellpadding="0" style="table-layout:fi...