当前位置:   article > 正文

vue3 笔记| el-table 控件 选中行高亮 设置选中行样式 获取选中行索引_el-table选中高亮

el-table选中高亮

选中行高亮 并且改样式

  1. <el-table :row-class-name="tableRowClassName" //获取索引,赋值用的
  2. :data="PeopleRt_noList"
  3. :header-cell-style="{background:'#A6A6A6',color:'#FFF', fontSize: '15px', fontWeight: 'bold', textAlign: 'center' ,border: '1px solid #A6A6A6'}"
  4. @row-click="selrow"
  5. border
  6. :table-layout="auto"
  7. :cell-style="{'text-align':'center' }" max-height="17.5vh" ref="Ttable"
  8. style="width: 100%"
  9. :row-key="getRowKey"
  10. highlight-current-row //这句选中行不同颜色
  11. >
  12. <el-table-column label="图示" width="180">
  13. <template #default="{ row }">
  14. <img :src="getPic(row.picrt)" alt="无图" width="100" height="50">
  15. </template>
  16. </el-table-column>
  17. <el-table-column prop="rt_no" label="工序" width="180" />
  18. <el-table-column prop="rt_name" label="名称" />
  19. </el-table>

然后在style中 设置选中行样式

  1. <style>
  2. ::v-deep .el-table__body tr.current-row>td {
  3. background: #BDDBBB !important;
  4. }
  5. </style>

获取选中行索引

el-table :row-class-name="tableRowClassName" 加上这句

然后在

  1. <script>
  2. methods:{
  3. tableRowClassName({
  4. row,
  5. rowIndex
  6. }) {
  7. row.index = rowIndex;
  8. },
  9. selrow(row, column, event) {
  10. // 处理点击事件的逻辑
  11. // const rowIndex = event.target.parentNode.rowIndex ;
  12. console.log('选中行的下标:' + row.index);
  13. this.dialogtablechange(row.index);
  14. // 其他逻辑...
  15. },
  16. }
  17. </script>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/114476?site
推荐阅读
相关标签
  

闽ICP备14008679号