如何使用Element实现表格表头添加搜索图标和功能

发布时间:2022-07-29 11:25:27 作者:iii
来源:亿速云 阅读:413

今天小编给大家分享一下如何使用Element实现表格表头添加搜索图标和功能的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

Element 表格表头添加搜索图标和功能

如何使用Element实现表格表头添加搜索图标和功能

如何使用Element实现表格表头添加搜索图标和功能

主要实现 table的slot=‘header’

<template>
    <el-table :data="tableData" >
        <template v-for="(headerItem, headerIndex) in headerData">
            <!-- 下拉框选择器 -->
            <el-table-column
                v-if="headerItem.select"
                :label="headerItem.label"
                :prop="headerItem.prop"
                :key="headerIndex"
            >
            	<!-- 表头的 slot -->
                <template #header>
                    <el-popover placement="bottom" title="请选择" width="200" trigger="click">
                        <div slot="reference" class="search-header">
                            <span class="search-title">{{ headerItem.label }}</span>
                            <i class="search-icon el-icon-search"></i>
                        </div>
                        <el-select v-model="headerItem.selectValue" placeholder="请选择">
                            <el-option
                                v-for="item in headerItem.selectOptions"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            >
                            </el-option>
                        </el-select>
                    </el-popover>
                </template>
                <!-- 表格的 内容 slot -->
                <template slot-scope="scope">
                    {{ scope.row[headerItem.prop] }}
                </template>
            </el-table-column>
            <!-- 日期选择器 -->
            <el-table-column
                v-else-if="headerItem.dateSelect"
                :label="headerItem.label"
                :prop="headerItem.prop"
                :key="headerIndex"
            >
                <template #header>
                    <el-popover placement="bottom" title="请选择" trigger="click">
                        <div class="search-box" slot="reference">
                            <span class="search-title">{{ headerItem.label }}</span>
                            <i class="el-icon-arrow-down search-icon"></i>
                        </div>
                        <el-date-picker
                            type="daterange"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                        >
                        </el-date-picker>
                    </el-popover>
                </template>
                <template slot-scope="scope">
                    {{ scope.row[headerItem.prop] }}
                </template>
            </el-table-column>
            <!-- 输入框 -->
            <el-table-column
                v-else-if="headerItem.inputSelect"
                :label="headerItem.label"
                :prop="headerItem.prop"
                :key="headerIndex"
            >
                <template #header>
                    <el-popover placement="bottom" title="请选择" trigger="click">
                        <div slot="reference" class="search-header">
                            <span class="search-title">{{ headerItem.label }}</span>
                            <i class="search-icon el-icon-search"></i>
                        </div>
                        <el-input />
                    </el-popover>
                </template>
                <template slot-scope="scope">
                    {{ scope.row[headerItem.prop] }}
                </template>
            </el-table-column>
            <el-table-column v-else :label="headerItem.label" :prop="headerItem.prop" :key="headerIndex">
            </el-table-column>
        </template>
    </el-table>
</template>

js代码

export default {
    data() {
        return {
            headerData: [
                {
                    label: '日期',
                    prop: 'date',
                    dateSelect: true,
                },
                {
                    label: '名称',
                    prop: 'name',
                    inputSelect: true,
                },
                {
                    label: '类型',
                    prop: 'type',
                    select: true,
                    selectValue: null,
                    selectOptions: [
                        {
                            value: 'Vue',
                            label: 'Vue',
                        },
                        {
                            value: 'React',
                            label: 'React',
                        },
                        {
                            value: 'Angular',
                            label: 'Angular',
                        },
                    ],
                },
            ],
            tableData: [
                {
                    date: '2016-05-02',
                    name: '王小虎',
                    type: 'Vue',
                },
                {
                    date: '2016-05-04',
                    name: '王小虎',
                    type: 'React',
                },
                {
                    date: '2016-05-01',
                    name: '王小虎',
                    type: 'Angular',
                },
            ],
        }
    },
}

element ui表格el-tabel给表头加icon图标

设置 Scoped slot 来自定义表头

<el-table :data="mockTableData" >
    <el-table-column prop="status">
        <template slot="header">类型 <i class="icon"></i></template>
    </el-table-column>
</el-table>

以上就是“如何使用Element实现表格表头添加搜索图标和功能”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注亿速云行业资讯频道。

推荐阅读:
  1. 如何使用vue实现element表格里表头信息提示功能
  2. layui数据表格实现重载数据表格功能(搜索功能)

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

element

上一篇:MySQL索引优化之适合构建索引的情况有哪些

下一篇:微信小程序自动化部署实例分析

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》