element ui table 单位格条件过滤后请求接口(filter-method、filter-change)

该文章介绍了如何在Vue.js应用中使用el-table组件进行数据展示,包括设置表格样式、处理条纹、固定列、自定义序号和过滤器。filterHandler函数用于过滤数据,而filterChanged监听筛选变化,适合作为触发更新数据源的时机。同时提醒,filterChanged内不应直接调用后端接口以防止无限循环。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<el-table
 class="tableBox" 
 ref="elTable" 
 :data="tableData" 
 v-loading="tableloading" 
 stripe 
 border
 row-key="conId" 
 @selection-change="handleSelectionChange"
 @filter-change="filterChanged"
 :header-cell-style="{ background: '#F5F7FA' }" style="font-size: 16px" 
 :row-style="{ height: '50px' }">
    <el-table-column type="selection" reserve-selection width="55" align="center">
    </el-table-column>
    <el-table-column label="序号" align="center" type="index" width="80" fixed>
       <template slot-scope="scope">
         <span>{{ (form.current - 1) * form.size + scope.$index + 1 }}</span>
       </template>
    </el-table-column>
    <el-table-column label="标题" show-overflow-tooltip min-width="400" column-key="title"
    :filters="[{ text: '默认', value: '默认' }, { text: '不推荐', value: '不推荐' }, { text: 
    '推荐', value: '推荐' }]" :filter-method="filterHandler" fixed>
          <template slot-scope="scope">
            <span class="hot">HOT</span>
          </template>
    </el-table-column>
  </el-table>

 js部分:

 filterHandler(value, row, column){
   //const property = column['property'];
   return row.type === value;
 },
 filterChanged(value){
 //value是一个对象,其key值为通过在el-table-column中设置的column-key属性,标志哪一个列的过滤条 
 件,可用于区分哪一个列的筛选条件发生了改变。
 //filterChanged函数和filter-method属性一般而言使用一个,前者可自定义筛选条件,如需要重新查库,则 
 比较适用,filter-method为el-table-column的属性函数,
 //其绑定的函数内部逻辑为:遍历表格绑定的数据,匹配表格每一行是否满足筛选条件,然后返回,所以上述示 
 例中的filterTag、filterChanged函数其实会重复执行,不可在其内部调用后端接口,否则会发生调用死循环。
  console.log(value.title)  //   {title:['默认','不推荐','推荐']}
  //请求接口
  this.getlist()
 },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值