VUE Element-ui table表上添加搜索框

背景:现在需要从table中的数据快速查出想要的数据

<el-table :data="assetTypeData.filter(data => !assetTypeSearch || data.model_type_name.toLowerCase().includes(assetTypeSearch.toLowerCase()))" style="width: 100%" max-height="250" >
    <el-table-column fixed prop="model_type_number" label="地点Id" width="80"></el-table-column>
    <el-table-column prop="model_type_name" label="存放地点" width="120"></el-table-column>
    <el-table-column align="right" >
        <template slot="header" slot-scope="scope">
            <el-input v-model="assetTypeSearch" size="mini" placeholder="输入关键字搜索" width="120"/>
        </template>
    </el-table-column>
</el-table>

注:

1、data绑定数据时需要用到 Element UI 封装的方法,语法为:

 :data="渲染数据.filter(data => !检索关键字||data.model_type_name.toLowerCase().includes(检索关键字.toLowerCase()))
当检索关键字不是字母时,可以去除 toLowerCase()转小写方法

实例:
 :data="assetTypeData.filter(data => !assetTypeSearch || data.model_type_name.toLowerCase().includes(assetTypeSearch.toLowerCase()))

2、assetTypeData值 与 assetTypeSearch值 都需要先定义在使用

Element UI官网:https://element.faas.ele.me/2.8/#/zh-CN/component/table 

猜你喜欢

转载自blog.csdn.net/qq_42715494/article/details/96272015