问题描述
iview table 如何在一定的条件下隐藏/显示某一整列
问题出现的环境背景及自己尝试过哪些方法
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
你期待的结果是什么?实际看到的错误信息又是什么?
在卡号没有时就只显示工号姓名两列及内容
iview table 如何在一定的条件下隐藏/显示某一整列
// 请把代码文本粘贴到下方(请勿用图片代替代码)
在卡号没有时就只显示工号姓名两列及内容
如果显示十行数据的话,你指的是这十行都没有卡号这个数据,然后把卡号这一列删除?
这很简单
假定你后端获取到数据list
1 来个变量sign=0
2 遍历list 看看每行的卡号的值是否都不存在,不存在的话sign+1
3 遍历完成后看sign是否等于list长度 等于的话 把columns删除掉卡号那一项
很简单,修改table的columns属性,根据你的条件去修改columns,需要则把那一列放上,否则删掉
隐藏/显示某一列的话则修改data属性,对于的那条数据删掉就好了
我只是一个搬运工
在iview.js中找到如下的columns那一部分替换为下面写的,就可以在多表头的情况下动态改变iview table绑定的columns
不知道是不是你想要的结果
I have found a solution1.open node_modulesiviewdistiview.js
2.find(near line:21336)
columns: {
handler: function handler() {
var colsWithId = this.makeColumnsId(this.columns);
this.allColumns = (0, _util.getAllColumns)(colsWithId);
this.cloneColumns = this.makeColumns(colsWithId);
this.columnRows = this.makeColumnRows(false, colsWithId);
this.leftFixedColumnRows = this.makeColumnRows('left', colsWithId);
this.rightFixedColumnRows = this.makeColumnRows('right', colsWithId);
this.rebuildData = this.makeDataWithSortAndFilter();
this.handleResize();
},
deep: true
},
3.replace with
columns: {
handler: function handler() {
//[Fix Bug]You may have an infinite update loop in watcher with expression "columns"
var tempClonedColumns = (0, _assist.deepCopy)(this.columns);
var colsWithId = this.makeColumnsId(tempClonedColumns);
//[Fix Bug End]
this.allColumns = (0, _util.getAllColumns)(colsWithId);
this.cloneColumns = this.makeColumns(colsWithId);
this.columnRows = this.makeColumnRows(false, colsWithId);
this.leftFixedColumnRows = this.makeColumnRows('left', colsWithId);
this.rightFixedColumnRows = this.makeColumnRows('right', colsWithId);
this.rebuildData = this.makeDataWithSortAndFilter();
this.handleResize();
},
deep: true
},
5 回答1.4k 阅读
5 回答1.3k 阅读✓ 已解决
2 回答837 阅读✓ 已解决
4 回答1.1k 阅读✓ 已解决
2 回答978 阅读✓ 已解决
4 回答944 阅读
1 回答1.8k 阅读
可以看下iview的table文档里“高级示例”
搬运代码如下: