element-plus中table多选实现

1、2、在封装的table组件中,

<el-table
    v-loading="loading"
    :data="tableData"
    v-bind="{ ...cfgProps }"
    :header-cell-style="{ height: 'var(--zn-table-header-height)', background: '#f5f5f5' }"
    :row-style="{ height: 'var(--zn-table-header-height)', border: 'none' }"
    :stripe="true"
    :height="height"
    :empty-text="emptyText"
    @row-click="onRowClick"
    @selection-change="handleSelectionChange"
    ref="multipleTableRef"
  >
</el-table>

<script setup lang="ts">
const multipleTableRef = ref(null)
const toggleRowSelection = (val) => {
  multipleTableRef.value.toggleRowSelection(val, true)
}

defineExpose({
  toggleRowSelection
})
</script>

3、关于使用toggleRowSelection勾选无效的问题:

a. 需要在下次DOM更新循环结束之后执行。

b. 通过从所有列表中找到需要选中的项来帮助选中,直接使用选中列表来设置会出错。

const setInitSelectKeys = async () => {
  await nextTick()
  props.initChecked.forEach((id) => {
    const item = recordList.value.find((n) => n.cultivationSubjectId === id)
    tableRef.value.toggleRowSelection(item)
  })
}

相关推荐

  1. element-ui】el-table实现跨页

    2024-04-08 19:36:01       52 阅读
  2. element ui el-table分页功能失效

    2024-04-08 19:36:01       45 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-08 19:36:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-08 19:36:01       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-08 19:36:01       82 阅读
  4. Python语言-面向对象

    2024-04-08 19:36:01       91 阅读

热门阅读

  1. 蜗牛-蓝桥每日真题

    2024-04-08 19:36:01       30 阅读
  2. c模板编程c/c++20240401

    2024-04-08 19:36:01       25 阅读
  3. SCP收容物999

    2024-04-08 19:36:01       35 阅读
  4. PTA C 1044 火星文翻译

    2024-04-08 19:36:01       41 阅读
  5. ES-7.12-官网阅读-ILM-index lifecycle actions

    2024-04-08 19:36:01       37 阅读
  6. 设计模式:单例模式

    2024-04-08 19:36:01       38 阅读
  7. 7-32 用天平找小球

    2024-04-08 19:36:01       24 阅读
  8. elasticSearch加入排序sort字段后报错

    2024-04-08 19:36:01       38 阅读
  9. Flutter 关键字

    2024-04-08 19:36:01       32 阅读