当前位置: 首页 > article >正文

el-table按照查询条件再对应行数据进行高亮,并可以定位到某行

需求:输入查询条件 点查询,满足模糊查询,将符合的数据筛选出来 并进行定位

      <div style="display: flex">
        <el-input v-model="searchData.content" clearable placeholder="零件特征" style="width: 12%;" />
        <el-input v-model="searchData.searchPara" clearable placeholder="扭矩值" style="width: 12%;" />
        <el-button
          icon="el-icon-search"
          @click="
            page = 1
            handlesearch()
          "
        />
      </div>
      <!-- 表格 -->
      <div class="tableDiv">
        <el-table
          ref="tableD"
          :data="tableData"
          :header-cell-style="{ background: '#F5F7FA', height: '30px' }"
          style="width: 100%; margin: 0 auto"
          height="100%"
          align="center"
          row-key="id"
          stripe
          border
          highlight-current-row
          :row-class-name="tableRowClassName"
          @select="handleSelectRow"
          @row-dblclick="handleRowClick"
        >
          <el-table-column type="selection" width="40" fixed />
          <el-table-column
            v-for="(item, index) in viewColumns"
            :key="index"
            :fixed="item.fixed"
            :prop="item.prop"
            :align="item.align"
            :label="item.label"
            :min-width="item.width"
            :show-overflow-tooltip="true"
          />
        </el-table>
      </div>
   // 查询的--- > 是做定位 并且红色的数据 不变,oldPartFeature只是一个记录的作用
    handlesearch() {
      if (this.searchData.content == '' && this.searchData.searchPara == '') return this.$message.warning('请输入查询值!')
      if (this.searchData.content && this.searchData.searchPara) {
        // 两个值都存在的情况下
        this.tableSearch()
      } else if (this.searchData.content && this.searchData.searchPara == '') {
        this.tableSearchContent()
      } else if (this.searchData.searchPara && this.searchData.content == '') {
        this.tableSearchPara()
      }
    },
    tableSearch() {
      const filterList = this.tableData.filter((item) => item?.part_feature.includes(this.searchData.content) && item?.make_mid.includes(this.searchData.searchPara))
      if (filterList.length == 0) return this.$message.warning('无匹配项')
      if (this.oldPartFeature == '' || this.oldPartFeature !== this.searchData.content || this.oldPartFeature !== this.searchData.searchPara) {
        this.oldPartFeature = JSON.parse(JSON.stringify(this.searchData.content || this.searchData.searchPara))
        this.ind = 0
      } else {
        if (this.ind >= filterList.length - 1) {
          this.idx = 0
        }
        this.tablelocation(filterList[this.idx])
        this.idx++
      }
    },
    tableSearchContent() {
      const filterList = this.tableData.filter((item) => item?.part_feature.includes(this.searchData.content))
      if (filterList.length == 0) return this.$message.warning('无匹配项')
      if (this.oldPartFeature == '' || this.oldPartFeature !== this.searchData.content) {
        this.oldPartFeature = JSON.parse(JSON.stringify(this.searchData.content))
        this.ind = 0
      } else {
        if (this.ind >= filterList.length - 1) {
          this.idx = 0
        }
        this.tablelocation(filterList[this.idx])
        this.idx++
      }
    },
    tableSearchPara() {
      const filterList = this.tableData.filter((item) => item.make_mid ? item.make_mid.includes(this.searchData.searchPara) : '')
      if (filterList.length == 0) return this.$message.warning('无匹配项')
      if (this.oldPartFeature == '' || this.oldPartFeature !== this.searchData.searchPara) {
        this.oldPartFeature = JSON.parse(JSON.stringify(this.searchData.searchPara))
        this.ind = 0
      } else {
        if (this.ind >= filterList.length - 1) {
          this.idx = 0
        }
        this.tablelocation(filterList[this.idx])
        this.idx++
      }
    },
//定位高亮
    tablelocation(data) {
      this.$refs.tableD.setCurrentRow(data)
      const rowIndex = this.tableData.findIndex((item) => {
        return item.id == data.id
      })
      const tableWrapperEL = this.$refs.tableD.bodyWrapper
      const EL = this.$refs.tableD.bodyWrapper.querySelectorAll('tbody tr')[rowIndex]
      const ELOffsetTop = EL.offsetTop
      console.log(tableWrapperEL)
      tableWrapperEL.scrollTo({
        left: 0,
        top: ELOffsetTop,
        behavior: 'smooth'
      })
    },


http://www.kler.cn/news/331067.html

相关文章:

  • C++20中头文件concepts的使用
  • 如何设置MySQL分布式架构主键ID,为什么不能使用自增ID或者UUID做主键?
  • 问题解决实录 | bash 中 tmux 颜色显示不全
  • 接口隔离原则(学习笔记)
  • Vue3轻松实现前端打印功能
  • 云原生之容器编排实践-OpenEuler23.09离线安装Kubernetes与KubeSphere
  • Windows 环境上安装 NASM 和 YASM 教程
  • unix中实际用户ID、有效用户ID、保存的设置用户ID的区别和作用
  • 风扇模块(直流5V STM32)
  • 怎么将bash(sh)的所有输出保存到log/txt中?
  • Shell脚本基础——实训项目任务
  • AI学习指南深度学习篇-批标准化的实现机制
  • 解决pycharm中matplotlab画图不能显示中文的错误
  • MeterSphere压测配置说明
  • Vue CLI项目创建指南:选择预设与包管理器(PNPM vs NPM)
  • 平面电磁波(解麦克斯韦方程)
  • JS基础练习|动态创建多个input,并且支持删除功能
  • 【C++】模拟实现红黑树
  • JDBC原生事务管理,类比超市购物来讲解(不常用,但作为基础还是要了解一下)
  • django搭建一个AI博客进行YouTube视频自动生成文字博客