加载页面时,我需要默认检查某些过滤条件。我已经通过this。$ refs.tableRC.columns [0] .filteredValue = this.filteredBranch设置了默认值,但是我不知道如何手动调用filterHandler()来过滤表数据?
<el-table ref="tableRC" :data="datalist" @filter-change="tableFilter">
<el-table-column label="Branch" :filters="branches" :column-key="'branch'" :filter-method="filterHandler">
......
tableFilter(filters) {
this.filteredBranch = filters.branch
},
filterHandler(value, row, column) {
return row.branch === value
},
getReqList() {
....
this.$refs.tableRC.columns[0].filteredValue = this.filteredBranch
....
}
最后,我找到了解决方法
if (Object.prototype.toString.call(this.filteredBranch) === '[object Array]') {
this.$refs.tableRC.columns[x].filteredValue = this.filteredBranch
this.$refs.tableRC.store.states.columns.forEach(column=> {
if (column.filteredValue && column.filteredValue.length) {
this.$refs.tableRC.store.commit('filterChange', {
column,
values: column.filteredValue,
silent: true
})
}
})
}