温馨提示×

温馨提示×

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

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

怎么在vue中利用element对table表格的动态列进行筛选

发布时间:2021-01-14 14:32:04 来源:亿速云 阅读:1758 作者:Leah 栏目:开发技术

怎么在vue中利用element对table表格的动态列进行筛选?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

实现代码:

HTML部分就是用一个多选框组件展示列选项
v-if="colData[i].istrue"控制显示隐藏,把列选项传到checkbox里再绑定勾选事件。

<el-popover placement="right" title="列筛选" trigger="click" width="420">            	<el-checkbox-group v-model="checkedColumns" size="mini">	<el-checkbox v-for="item in checkBoxGroup" :key="item" :label="item" :value="item"></el-checkbox>	</el-checkbox-group>	<el-button slot="reference" type="primary" size="small" plain><i class="el-icon-arrow-down el-icon-menu" />列表项展示筛选</el-button> </el-popover>
<el-table :data="attendanceList" @sort-change="sort" highlight-current-row :row-class-name="holidayRow" @selection-change="editAll" ref="multipleTable">	<el-table-column type="selection" width="55" align="center"></el-table-column>	<el-table-column label="员工基本信息">	<el-table-column v-if="colData[0].istrue" align="center" prop="user_id" label="工号" width="80" fixed></el-table-column>	<el-table-column v-if="colData[1].istrue" align="center" prop="name" label="姓名" width="80" fixed></el-table-column>	<el-table-column v-if="colData[2].istrue" align="center" prop="age" label="年龄" width="60"></el-table-column>	<el-table-column v-if="colData[3].istrue" align="center" prop="gender" label="性别" width="80"></el-table-column>	<el-table-column v-if="colData[4].istrue" align="center" prop="department" label="部门名称" width="100"></el-table-column>	</el-table-column>	......

js 数据存放的data部分

//列表动态隐藏	 colData: [	   { title: "工号", istrue: true },	   { title: "姓名", istrue: true },	   { title: "年龄", istrue: true },	   { title: "性别", istrue: true },	   { title: "部门名称", istrue: true },	   	 ],	 checkBoxGroup: [],	 checkedColumns: [],

js 方法实现部分

created() {      	  // 列筛选	  this.colData.forEach((item, index) => {	    this.checkBoxGroup.push(item.title);	    this.checkedColumns.push(item.title);	  })	  this.checkedColumns = this.checkedColumns	  let UnData = localStorage.getItem(this.colTable)	  UnData = JSON.parse(UnData)	  if (UnData != null) {	    this.checkedColumns = this.checkedColumns.filter((item) => {	      return !UnData.includes(item)	    })	  }	},  // 监控列隐藏  watch: {    checkedColumns(val,value) {      let arr = this.checkBoxGroup.filter(i => !val.includes(i)); // 未选中      localStorage.setItem(this.colTable, JSON.stringify(arr))      this.colData.filter(i => {        if (arr.indexOf(i.title) != -1) {          i.istrue = false;        } else {          i.istrue = true;        }      });    }  },

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。

向AI问一下细节

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

AI