在做管理后台开发的时候会碰到这样的一个需求,这个表格展示的数据太长了,用户想加个筛选管理这个表格长度。
类似截图:
而element在table组件中有提供render-header这个方法。
废话不多说直接上代码
renderHeader(h, obj) {
if (obj.column.label == '操作') {
return h('div', {}, [
h('el-popover', {
props: {
placement: "bottom",
width: "150",
trigger: "click",
},
},
[
h('span', {
slot: 'reference',
class: 'ces-table-require',
domProps: {
innerHTML: obj.column.label + '<i class="el-icon-s-tools pl10"/>'
}
}),
h('el-checkbox-group', {
class: 'bdb_m20',
style: {
'margin-bottom': '10px',
'border-bottom': '1px solid #efefef',
'padding-bottom': '10px'
},
props: {
'value': this.check,
},
}, [
this.checkList.map((item, index) => {
return h('el-checkbox', {
props: {
label: item.label,
'true-label': item.label,
key: index,
disabled: index == this.checkList.length - 1 ? true : false,
checked: this.check[index] == item.label ? true : false
},
on: {
change: val => {
if (val) {
this.check.push(item.label)
this.check = [...new Set(this.check)]
} else {
let i = this.check.findIndex(row => row == item.label)
this.check.splice(i, 1)
}
}
},
})
})
]),
h('el-button', {
props: {
size: "mini"
},
on: {
click: _ => {
this.check = []
this.$parent.tableCols = this.checkList
}
},
domProps: {
innerHTML: '复原'
}
}),
h('el-button', {
props: {
size: "mini",
type: "primary"
},
on: {
click: _ => {
let arr = this.tableCols.filter(item => !this.check.some(ele => ele === item.label))
this.$parent.tableCols = arr
}
},
domProps: {
innerHTML: '隐藏'
}
})
])
])
} else {
return h("span", {}, obj.column.label)
}
},
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。