xqy183011

vue中table表格做定位处理

需求:前端根据搜索条件中的partNo的值,进行定位查询到table列表中对应的每一行

search(){
  if(this.positionIndx.length==0){
    this.tableData.forEach((item,index)=>{
      if(item.partNo == this.queryForm.partNo){
        this.positionIndx.push(index)                        // 定义一个空数组 positionIndx 用来保存相同partNo的下标;
      }
    })
  }
  if (this.tableData.length > 0) {
    if (this.queryForm.partNo !== \'\') {
      if (this.$refs[\'selectPartRefs\']) {
        let vmEl = this.$refs[\'selectPartRefs\'].$el            // selectPartRefs 是table中绑定的ref的值,一定要保持一致;
        //计算滚动条的位置
        const targetTop = vmEl.querySelectorAll(\'.el-table__body tr\')[this.positionIndx[this.inPosition]].getBoundingClientRect().top    // 找到table中的每一行利用下标来计算每一行的距离视口的高度;
        const containerTop = vmEl.querySelector(\'.el-table__body\').getBoundingClientRect().top
        const scrollParent = vmEl.querySelector(\'.el-table__body-wrapper\')
        scrollParent.scrollTop = targetTop - containerTop;
        this.inPosition++;                                     // 首先在data中定义 inPosition = 0 ,每次点击search按钮的时候,让下标进行++操作,以遍定位到下一个匹配的partNO;
        if( this.inPosition >= this.positionIndx.length ){
          this.inPosition = 0;                                 // 所有的都遍历完成以后,让定位回到第一个匹配的partNo的行上,以此达到可以循环定位的效果;
        }
      }
    } else {
      this.$message({
        type: \'error\',
        message:\'Please enter the partNo of the query\'
      })
    }
  }
},

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-11-13
  • 2021-11-23
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-26
  • 2021-12-26
  • 2021-05-19
  • 2021-10-16
  • 2022-12-23
  • 2021-06-15
相关资源
相似解决方案