zoukankan      html  css  js  c++  java
  • element ui table+分页 筛选全部数据

    1. @filter-change 要写在table根元素,也就是<el-table @filter-change="filterChange"></el-table>

    2. 需要筛选的项,要写上 :column-key=" ' aaa ' " 

    3. 要搜索全局,就要去掉对应筛选项的 :filter-method="xx"。 

    ps:   filter-method 筛选当前页面,不会请求后端接口,条数多的话,会造成死循环

    demo如下

    <template>
        <div class="app-container">
            <div class="button-interval">
                <el-row>
                    <el-input v-model="search" placeholder="请输入搜索内容......"
                              class="search-input"
                              @keyup.enter.native="fliterData"/>
                </el-row>
            </div>
    
            <el-table
                    v-loading="listLoading"
                    ref="myTable"
                    :data="blist | dataslice(listQuery.page, listQuery.limit)"
                    element-loading-text="拼命加载中......"
                    border
                    fit
                    highlight-current-row
                    @filter-change="fliterChange"
            >
                <el-table-column align="center" label="ID" prop="id" v-if="false"/>
                <el-table-column align="center" label="主机IP" prop="ip"/>
                <el-table-column align="center" label="主机名" prop="hostname"/>
                <el-table-column align="center" label="主机类型" prop="hosttype"
                                 :filters="hosttype_filters" filter-placement="bottom-end"
                                 column-key="hosttype" :filter-multiple="false"/>
               <!--
            ......
            -->
    <el-table-column align="center" label="创建时间" prop="create_time" sortable/> <el-table-column align="center" label="更新时间" prop="update_time" sortable/> </el-table> <!-- 前端分页 --> <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" /> </div> </template> <script> import {queryHost} from '@/api/hostmanage' import Pagination from '@/components/Pagination' export default { name: 'HostList', components: {Pagination}, filters: { dataslice(array, page, limit) { const offset = (page - 1) * limit const newdata = (offset + limit >= array.length) ? array.slice(offset, array.length) : array.slice(offset, offset + limit) return newdata } }, data() { return { list: [], blist: [], listLoading: true, total: 0, search: undefined, listQuery: { page: 1, limit: 10, }, hosttype_filters: [{text: '代理服务器', value: '代理服务器'}, {text: '普通服务器', value: '普通服务器'}], } }, watch: { search: function () { this.fliterData() } }, created() { this.fetchData(); }, methods: { // 异步表格获取数据 fetchData() { this.listLoading = true queryHost().then(response => { this.list = response.data this.blist = response.data this.listLoading = false this.total = response.data.length }) }, fliterData() { const search = this.search if (search) { this.blist = this.list.filter(data => { return Object.keys(data).some(key => { return String(data[key]).toLowerCase().indexOf(search) > -1 }) }) this.total = this.blist.length return this.blist } this.blist = this.list this.total = this.blist.length return this.list }, fliterChange(filters){ const filterskey = filters.hosttype console.log(filterskey) if (filterskey.length>0) { this.blist = this.list.filter(data => { return Object.keys(data).some(key => { return data['hosttype'] ===filterskey[0] }) }) this.total = this.blist.length return this.blist } this.blist = this.list this.total = this.blist.length return this.list } } } </script>
  • 相关阅读:
    【Linux】linux中很有用的指令(练习)
    【C 标准库】<string.h>
    【Linux网络编程】使用GDB调试程序
    【LINUX网络编程】Makefile文件
    【UNIX网络编程】TCP客户/服务器程序示例
    【UNIX网络编程】基本TCP套接字编程
    pyQt5新手教程 (二)通过jupyter开始你的旅程-编写一个空白窗口
    pyQt5新手教程 (一)通过anaconda安装pyqt包
    如何把没用的tplink4C68路由器连起来
    xcode10升级之后开始安装cocoapods
  • 原文地址:https://www.cnblogs.com/cherylgi/p/13572445.html
Copyright © 2011-2022 走看看