一个基于iView Table 的带搜索过滤的Table组件

iview-filter-table

一个基于iView Table 的带搜索过滤的Table组件, 支持 Input输入框、Select下拉框、DatePicker时间框三种表格筛选方式.

使用

模板

<div>
  <FilterTable :columns="columns" :data="data" @on-search="onSearch"></FilterTable>
</div>

列描述数据对象:

ageOptions = [
    {
        value: '',
        name: '全部'
    },
    {
        value: 18,
        name: '18'
    },
    {
        value: 26,
        name: '26'
    },
    {
        value: 30,
        name: '30'
    },
];

columns = [
    {
        title: "姓名",
        key: "name",
        width: this.columnWidth,
        filter: {
            type: 'Input',
            stype: 'text',
            placeholder: '请输入姓名',
            size: this.tableSize,   // 和table的size尽量一致
            margin: '5px auto',
        }
    },
    {
        title: "日期",
        key: "date",
        width: this.columnWidth,
        filter: {
            type: 'DatePicker',
            stype: 'date',
            placeholder: '选择日期',
            size: this.tableSize,   // 和table的size尽量一致
            margin: '5px auto',
        }
    },
    {
        title: "地址",
        key: "address",
        width: this.columnWidth,
        filter: {
            type: 'Input',
            stype: 'text',
            placeholder: '请输入地址',
            size: this.tableSize,   // 和table的size尽量一致
            margin: '5px auto',
        }
    },
    {
        title: "家庭地址",
        key: "homeAddress",
        stype: 'text',
        width: this.columnWidth,
        filter: {
            type: 'Input',
            placeholder: '请输入地址',
            size: this.tableSize,   // 和table的size尽量一致
            margin: '5px auto',
        }
    },
    {
        title: "年龄",
        key: "age",
        width: this.columnWidth,
        filter: {
            type: 'Select',
            options: this.ageOptions,
            placeholder: '请选择',
            size: this.tableSize,   // 和table的size尽量一致
            margin: '5px auto',
        }
    },
    {
        title: "功能",
        key: "action",
        width: 150,
        align: 'center',
        fixed: "right",
        render: (h, params) => {
            return h("div", [
                h("Button", {
                    props: {
                        type: "primary",
                        size: "small"
                    },
                    style: {
                        marginRight: "5px"
                    },
                    on: {
                        click: () => {
                            this.showIndex(params.index)
                        }
                    }
                }, "View"),
                h("Button", {
                    props: {
                        type: "error",
                        size: "small"
                    },
                    on: {
                        click: () => {
                            this.removeIndex(params.index)
                        }
                    }
                }, "Delete")
            ]);
        }
    }
];

下拉框数据:

ageOptions = [
    {
        value: '',
        name: '全部'
    },
    {
        value: 18,
        name: '18'
    },
    {
        value: 26,
        name: '26'
    },
    {
        value: 30,
        name: '30'
    },
];

触发搜索事件:

        onSearch(search) {
            let data = [];
            for (let item of this.data1) {
                if (this.screen(Object.values(item), Object.values(search))) {
                    data.push(item)
                }
            }
            this.data = data;
        }

在该方法中进行条件过滤,更新data 属性的值。

直接运行该项目可以看当前组件的Table效果。

image-20190403103056324
image-20190403103126114

Project setup

npm install

Compiles and hot-reloads for development

npm run serve

Compiles and minifies for production

npm run build

Run your tests

npm run test

Lints and fixes files

npm run lint

Run your unit tests

npm run test:unit

Customize configuration

See Configuration Reference.

Github源码地址 <https://github.com/xinlei3166/iview-filter-table

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 10,740评论 4 57
  • 怎样学会使用这个词? 1)翻译下面的句子: 很多 CEO 希望能够找到解决企业所有问题的万能药。 (参考翻译:Ma...
    微醺x阅读 108评论 0 0
  • 文、图/伊儿 蒲公英高高举着冠毛泡泡,散立在墨绿色的草丛里,躲在阳光下,一动不动。 远处的山保持着平衡,蒲公英的种...
    伊儿A阅读 1,521评论 24 31
  • 晋朝有一个人非常喜欢结交朋友,并经常请朋友到家里喝酒聊天,这个人名叫乐广。 一天,乐广做了一桌子的好菜,又邀请了好...
    王老师_ff16阅读 4,497评论 8 66
  • 善知识〈注1〉: 近来听到关于能〈注2〉的证道偈的一些流言,写此信不为了自证清白,只是为了澄清一些误解,以...
    梵花若净阅读 967评论 6 17