关于elementUI 分页 table 使用 toggleRowSelection

我出现问题的前提

在table表格第一页全选 ,第二页全选 回到第一页

点击按钮 取消 第一页,第二页我不要的勾选

初始实现

this.selectedPeraonal是表格 selection-change方法返回的值

javascript 复制代码
handleSelectionChange(val) {
    this.selectedPeraonal = val || []
},

onlineFeedBack(){
    const selectedPeraonal = this.selectedPeraonal.filter(item => !errId.includes(item['welfare_id']))  
    this.$refs['generalTable'].$refs.generalTable.clearSelection()
    this.$nextTick(() => {
        selectedPeraonal.map(item => {
            this.$refs['generalTable'].$refs.generalTable.toggleRowSelection(item,true)
        })
        this.loadingOnLineFeed = false
    })
}

但是 页面未生效

了解到

toggleRowSelection 传入的item必须是当前table表格中的数据才会生效

所以filter 之后就不算当前table的数据了

换个思路

javascript 复制代码
this.$nextTick(() => {
//  toggleRowSelection中传入记录的数据,并不会生效,要传入当前table表格中的数据才会生效
    for (let i = this.selectedPeraonal.length - 1; i >= 0; i--) {
        const item = this.selectedPeraonal[i]
        if (errId.includes(item['welfare_id'])) {                                      
            this.$refs['generalTable'].$refs.generalTable.toggleRowSelection(item, false)
        }
    }
    this.loadingOnLineFeed = false
})
相关推荐
摸着石头过河的石头3 小时前
函数的超能力:JavaScript高阶函数完全指南
前端·javascript
汤姆Tom3 小时前
写这么多年CSS,都不知道什么是容器查询?
前端·css·面试
进击的二向箔3 小时前
Vue 3 深度解析:Composition API 如何改变前端开发方式
前端
golang学习记3 小时前
从0死磕全栈之Next.js 表单开发终极指南:使用 Server Actions 构建高效、安全、现代化的表单
前端
纯爱掌门人3 小时前
我把前端踩坑经验总结成28条“涨薪秘籍”,老板夸同事赞,新手照着做准没错
前端·程序员·代码规范
LuckySusu3 小时前
【vue篇】Vue 模板编译全解析:从 Template 到 DOM 的奇妙旅程
前端·vue.js
LuckySusu3 小时前
【vue篇】Vue 响应式更新揭秘:数据变了,DOM 为何不立即刷新?
前端·vue.js
LuckySusu3 小时前
【vue篇】Vue 事件修饰符完全指南:精准控制事件流
前端·vue.js
6269603 小时前
前端页面出现问题ResizeObserver loop completed with undelivered notifications.
前端
LuckySusu3 小时前
【vue篇】Vue 组件继承与混入:mixin 与 extends 的合并逻辑深度解析
前端·vue.js