欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 时评 > el-table按照查询条件再对应行数据进行高亮,并可以定位到某行

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

2024/10/26 0:19:12 来源:https://blog.csdn.net/dy1717/article/details/142640807  浏览:    关键词: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-buttonicon="el-icon-search"@click="page = 1handlesearch()"/></div><!-- 表格 --><div class="tableDiv"><el-tableref="tableD":data="tableData":header-cell-style="{ background: '#F5F7FA', height: '30px' }"style="width: 100%; margin: 0 auto"height="100%"align="center"row-key="id"stripeborderhighlight-current-row:row-class-name="tableRowClassName"@select="handleSelectRow"@row-dblclick="handleRowClick"><el-table-column type="selection" width="40" fixed /><el-table-columnv-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.bodyWrapperconst EL = this.$refs.tableD.bodyWrapper.querySelectorAll('tbody tr')[rowIndex]const ELOffsetTop = EL.offsetTopconsole.log(tableWrapperEL)tableWrapperEL.scrollTo({left: 0,top: ELOffsetTop,behavior: 'smooth'})},

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com