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 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章