vue + elementui 实现 el-table 表格动态表头筛选功能

本文介绍了一段关于使用Element UI构建的数据表格,展示了如何实现字段级别的筛选功能,以及如何根据条件动态调整表头内容。通过`el-table`组件,实现了单选或多选筛选,针对不同字段(如资格状态、意向等级和电话状态)定制过滤选项。
摘要由CSDN通过智能技术生成

在这里插入图片描述

<el-table ref="table" v-loading="listLoading"
                      :cell-style="cellStyle"
                      :data="tableData"
                      :header-cell-style="table_heard_style"
                      :row-class-name="tableRowClassName" :row-key="row_key"
                      :span-method="arraySpanMethod"
                      border
                      class="btns_siyou"
                      element-loading-text="拼命加载中"
                      highlight-current-row
                      size="mini"
                      style="width: 100%" @select="selectCheckOne" @select-all="selectAll"
                      @sort-change="sortChangeFn"
                      @filter-change="filterChange"
            >
              <el-table-column :resizable="false" type="selection" width="50"></el-table-column>
              <!--循环表头-->
              <template v-for="(item, index) in tableHead">
              //判断哪一列需要筛选功能
                <el-table-column v-if="item.field == 'qualificationStatus'" :key="index"
                                 :column-key="item.field"
                                 :filter-multiple="false"
                                 :filters="zzqkdata2" :label="item.fieldName" :min-width="minWidthFn(item)"
                                 :property="item.field"
                                 filter-placement="top-end"
                >
                  <template slot-scope="scope"></template>
                </el-table-column>
                //filter-multiple 是否多选
                //filters 筛选数组
                <el-table-column v-else-if="item.field == 'intentionLevel'" :key="index"
                                 :column-key="item.field"
                                 :filter-multiple="false"
                                 :filters="yixData2" :label="item.fieldName" :min-width="minWidthFn(item)"
                                 :property="item.field"
                                 filter-placement="top-end"
                >
                  <template slot-scope="scope"></template>
                </el-table-column>
                <el-table-column v-else-if="item.field == 'callStatus'" :key="index"
                                 :column-key="item.field"
                                 :filter-multiple="false"
                                 :filters="phoneTelData2" :label="item.fieldName" :min-width="minWidthFn(item)"
                                 :property="item.field"
                                 filter-placement="top-end"
                >
                  <template slot-scope="scope"></template>
                </el-table-column>
                //其他列
                <el-table-column v-else :key="index" :label="item.fieldName" :min-width="minWidthFn(item)"
                                 :property="item.field"
                                 :sortable="sortAbleFn(item)"
                >
                  <template slot-scope="scope">
                    <!--企业名称-->
                    <span v-if="item.fieldName === '企业名称'">...</span>
                    <!--联系方式-->
                    <span v-else-if="item.fieldName === '联系方式'">...</span>
                    <!--否则-->
                    <span v-else>{{ scope.row[scope.column.property] === "" ? "--" : scope.row[scope.column.property] }}</span>
                  </template>
                </el-table-column>
// table表头筛选条件触发事件
    filterChange(filters) {
      let data = JSON.parse(JSON.stringify(this.tableDatasList))
      let aaa = {text: '', value: ''}
      let $select = Object.keys(filters)[0]
      //代码待优化,,,哈哈哈哈哈
      if ($select == "qualificationStatus") {
        aaa = this.zzqkdata2.find(val => filters.qualificationStatus[0] == val.value)
        data.companyType = !this.isobjEmpty(aaa) ? aaa.value : ''
      } else if ($select == "intentionLevel") {
        aaa = this.yixData2.find(val => filters.intentionLevel[0] == val.value)
        data.followQueryInfo.intentionLevel = !this.isobjEmpty(aaa) ? aaa.value : ''
      } else if ($select == "callStatus") {
        aaa = this.phoneTelData2.find(val => filters.callStatus[0] == val.value)
        data.followQueryInfo.callStatus = !this.isobjEmpty(aaa) ? aaa.value : ''
      } else {
      }
      this.tableHead.forEach(val => {
        if (val.field == $select) {
          if (this.isobjEmpty(aaa)) {
            aaa = {text: '', value: ''}
            if ($select == "qualificationStatus") {
              aaa.text = '有无资质'
            } else if ($select == "intentionLevel") {
              aaa.text = '意向度'
            } else if ($select == "callStatus") {
              aaa.text = '电话状态'
            } else {
            }
          }
          val.fieldName = aaa.text
        }
      })
      this.pageNum = 0
      this.currentPage4 = 1
      this.tableDatasList = JSON.parse(JSON.stringify(data))
      this.getListTable(data)
    },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值