iview的table的表头加下拉搜索操作等功能

iview的table的表头加下拉搜索操作等功能

先上一张效果图:

在这里插入图片描述

代码部分:

<template>
    <Table :columns="columns1" :data="data1"></Table>
</template>

export default {
       data () {
           return {
               headerPersonVisible:false,
               headerSearchVisible:false,
               clickIsSearchBtn:false,
               verticalSearch: '全部可检索',
               columns1: [
                   {
                       title: 'Name',
                       key: 'name',
                       align: 'center',
                       renderHeader: (h, params) => {
                           return h('Dropdown',
                               {
                                   props:
                                       {
                                           transfer: true,
                                           trigger: 'custom',
                                           visible: this.headerPersonVisible
                                       }
                               },
                               [
                                   h('a',
                                       {
                                           style: {
                                               color: '#333'
                                           },
                                           on: {
                                               click: ($event) => {
                                                   $event.stopPropagation();
                                                   this.headerPersonVisible = !this.headerPersonVisible;
                                               }
                                           },
                                       }, '名称'),
                                   h('Icon', {
                                       props: {
                                           type: 'ios-funnel'
                                       },
                                       style: {
                                           marginLeft: '5px',
                                           fontSize: '14px',
                                           color: '#c5c8ce',
                                           cursor: 'pointer'
                                       },
                                       on: {
                                           click: ($event) => {
                                               $event.stopPropagation();
                                               this.headerPersonVisible = !this.headerPersonVisible;
                                           }
                                       }
                                   }),
                                   h('DropdownMenu', {slot: 'list'},
                                       [
                                           h('DropdownItem', {
                                               class: 'myDropdown',
                                               style: {
                                                   fontSize: '14px !important',
                                                   textAlign: 'left'
                                               },
                                               nativeOn: {
                                                   click: (name) => {
                                                       //console.log(name);
                                                   }
                                               },
                                           }, [
                                               h('Input',
                                                   {
                                                       domProps:{
                                                           id:'personInput'
                                                       }
                                                   },
                                                   {
                                                       props: {
                                                           placeholder: "请输入内容",
                                                       },
                                                       on: {
                                                           'on-blur': (event) => {
                                                               //console.log(event);
                                                           }
                                                       },
                                                   }
                                               ),
                                               h('div', {
                                                       style: {
                                                           textAlign: 'center',
                                                           marginTop: '10px'
                                                       }
                                                   },
                                                   [
                                                       h('Button', {
                                                           props: {
                                                               size: 'small'
                                                           },
                                                           style: {
                                                               fontSize: '14px',
                                                               marginTop: '10px',
                                                               marginRight: '10px'
                                                           },
                                                           on: {
                                                               click: ($event) => {
                                                                   $event.stopPropagation();
                                                                   this.headerPersonVisible = false;
                                                               }
                                                           }
                                                       }, '筛选'),
                                                       h('Button', {
                                                           props: {
                                                               type: 'primary',
                                                               size: 'small'
                                                           },
                                                           style: {
                                                               fontSize: '14px',
                                                               marginTop: '10px'
                                                           },
                                                           on: {
                                                               click: ($event) => {
                                                                   $event.stopPropagation();
                                                                   this.headerPersonVisible = false;
                                                               }
                                                           }
                                                       }, '重置')
                                                   ])
                                           ])
                                       ]
                                   )
                               ])
                       }
                   },
                   {
                       title: 'isSearch',
                       key: 'isSearch',
                       align: 'center',
                       renderHeader: (h, params) => {
                           return h('Dropdown',
                               {
                                   props:
                                       {
                                           transfer: true,
                                           trigger: 'custom',
                                           visible: this.headerSearchVisible
                                       }
                               },
                               [
                                   h('a',
                                       {
                                           style: {
                                               color: '#333'
                                           },
                                           on: {
                                               click: ($event) => {
                                                   $event.stopPropagation();
                                                   this.headerSearchVisible = !this.headerSearchVisible;
                                                   this.clickIsSearchBtn = false;
                                               }
                                           },
                                       }, '可检索'),
                                   h('Icon', {
                                       props: {
                                           type: 'ios-arrow-down'
                                       },
                                       style: {
                                           marginLeft: '5px',
                                           fontSize: '14px',
                                           color: '#333',
                                           cursor: 'pointer'
                                       },
                                       on: {
                                           click: ($event) => {
                                               $event.stopPropagation();
                                               this.headerSearchVisible = !this.headerSearchVisible;
                                               this.clickIsSearchBtn = false;
                                           }
                                       }
                                   }),
                                   h('DropdownMenu', {slot: 'list'},
                                       [
                                           h('DropdownItem', {
                                               class: 'myDropdown',
                                               style: {
                                                   fontSize: '14px !important',
                                                   textAlign: 'left'
                                               },
                                               nativeOn: {
                                                   click: (name) => {
                                                       //console.log(name);
                                                   }
                                               },
                                           }, [
                                               h('RadioGroup', {
                                                       props: {
                                                           value: this.verticalSearch,
                                                           vertical: true
                                                       },
                                                       on: {
                                                           'on-change': (status) => {
                                                               //console.log(status);
                                                               this.verticalSearch = status;
                                                           }
                                                       }
                                                   },
                                                   [
                                                       h('Radio', {
                                                           props: {
                                                               label: '全部可检索'
                                                           }
                                                       }, '全部可检索'),
                                                       h('Radio', {
                                                           props: {
                                                               label: '全部不可检索'
                                                           }
                                                       }, '全部不可检索')
                                                   ]
                                               ),
                                               h('div', [
                                                   h('Button', {
                                                       props: {
                                                           size: 'small'
                                                       },
                                                       style: {
                                                           fontSize: '14px',
                                                           marginTop: '10px',
                                                           marginRight: '10px'
                                                       },
                                                       on: {
                                                           click: ($event) => {
                                                               $event.stopPropagation();
                                                               this.headerSearchVisible = false;
                                                           }
                                                       }
                                                   }, '取消'),
                                                   h('Button', {
                                                       props: {
                                                           type: 'primary',
                                                           size: 'small'
                                                       },
                                                       style: {
                                                           fontSize: '14px',
                                                           marginTop: '10px'
                                                       },
                                                       on: {
                                                           click: ($event) => {
                                                               $event.stopPropagation();
                                                               this.headerSearchVisible = false;
                                                               this.clickIsSearchBtn = true;
                                                               if (this.verticalSearch === "全部可检索") {
                                                                   sessionStorage.setItem("isSearch", "1")
                                                               } else if (this.verticalSearch === "全部不可检索") {
                                                                   sessionStorage.setItem("isSearch", "0")
                                                               }
                                                           }
                                                       }
                                                   }, '确定')
                                               ])
                                           ])
                                       ]
                                   )
                               ])
                       },
                       render: (h, params) => {
                           let status = params.row.isSearch; //1是可 0是不可
                           //点击确定按钮时,将可检索这一列的所有状态全部设置成所选择的状态
                           if(this.clickIsSearchBtn){
                               this.headerSearchVisible = false;
                               this.clickIsSearchBtn = false;
                               if (this.verticalSearch === "全部可检索") {
                                   status = 1;
                               } else if (this.verticalSearch === "全部不可检索") {
                                   status = 0;
                               }
                           }

                           if(parseInt(sessionStorage.getItem("isSearch")) === 0){
                               if(this.data1.length>0){
                                   this.data1.map(function(item){
                                       item.isSearch= 0
                                   });
                               }
                           }else if(parseInt(sessionStorage.getItem("isSearch")) === 1){
                               if(this.data1.length>0){
                                   this.data1.map(function(item){
                                       item.isSearch= 1
                                   });
                               }
                           }

                           if (status === 1) {
                               return h('span', [
                                   h('Icon', {
                                       props: {
                                           type: "md-checkmark"
                                       },
                                       style: {
                                           marginRight: '8px',
                                           marginTop: '-3px',
                                           color: '#19be6b',
                                           fontSize: '18px',
                                           cursor: 'pointer'
                                       },
                                       on: {
                                           click: ($event) => {
                                               $event.stopPropagation();
                                               if ($event.target.className === "ivu-icon ivu-icon-md-checkmark") {
                                                   $event.target.className = "ivu-icon ivu-icon-md-close";
                                               } else if ($event.target.className === "ivu-icon ivu-icon-md-close") {
                                                   $event.target.className = "ivu-icon ivu-icon-md-checkmark";
                                               }
                                           }
                                       }
                                   })
                               ])
                           }
                           if (status === 0) {
                               return h('span', [
                                   h('Icon', {
                                       props: {
                                           type: "md-close"
                                       },
                                       style: {
                                           marginRight: '8px',
                                           marginTop: '-3px',
                                           color: '#ed4014',
                                           fontSize: '18px',
                                           cursor: 'pointer'
                                       },
                                       on: {
                                           click: ($event) => {
                                               $event.stopPropagation();
                                               if ($event.target.className === "ivu-icon ivu-icon-md-checkmark") {
                                                   $event.target.className = "ivu-icon ivu-icon-md-close";
                                               } else if ($event.target.className === "ivu-icon ivu-icon-md-close") {
                                                   $event.target.className = "ivu-icon ivu-icon-md-checkmark";
                                               }
                                           }
                                       }
                                   })
                               ])
                           }
                       }
                   },
                   {
                       title: 'Address',
                       key: 'address',
                       align: 'center'
                   }
               ],
               data1: [
                   {
                       name: 'John Brown',
                       isSearch: 1,
                       address: 'New York No. 1 Lake Park',
                       date: '2016-10-03'
                   },
                   {
                       name: 'Jim Green',
                       isSearch: 0,
                       address: 'London No. 1 Lake Park',
                       date: '2016-10-01'
                   },
                   {
                       name: 'Joe Black',
                       isSearch: 0,
                       address: 'Sydney No. 1 Lake Park',
                       date: '2016-10-02'
                   },
                   {
                       name: 'Jon Snow',
                       isSearch: 1,
                       address: 'Ottawa No. 2 Lake Park',
                       date: '2016-10-04'
                   }
               ]
           }
       }
    }
第一次写博客文章,后续希望自己勤快点多写写吧~
  • 5
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值