x-extends / vxe-table

Vxe table 的表格组件
https://vxetable.cn
MIT License
7.67k stars 1.06k forks source link

官方案例中树型复选框 默认选中,通过指定 checkRowKeys 设置默认选中的行,实际上最底层的数据没有勾选上 #2591

Open xjie0626 opened 1 month ago

xjie0626 commented 1 month ago

可复现的链接(包含复现链接与示例代码):

https://vxetable.cn/#/component/table/tree/checkbox

问题描述与截图:

checkRowKeys: [10053, 23666]选中了test abc96和Test8 但实际上没有勾上

<template>
  <div>
    <vxe-table
      ref="tableRef"
      :row-config="{keyField: 'id'}"
      :column-config="{resizable: true}"
      :data="tableData"
      :tree-config="{transform: true}"
      :checkbox-config="{labelField: 'name', checkRowKeys: [10053, 23666]}"
      @checkbox-change="selectChangeEvent">
      <vxe-column type="checkbox" title="Sex" width="400" tree-node></vxe-column>
      <vxe-column field="size" title="Size"></vxe-column>
      <vxe-column field="type" title="Type"></vxe-column>
      <vxe-column field="date" title="Date"></vxe-column>
    </vxe-table>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { VxeTableInstance, VxeTableEvents } from 'vxe-table'

interface RowVO {
  id: number
  parentId: number | null
  name: string
  type: string
  size: number
  date: string
}

const tableRef = ref<VxeTableInstance<RowVO>>()

const tableData = ref<RowVO[]>([
  { id: 10000, parentId: null, name: 'test abc1', type: 'mp3', size: 1024, date: '2020-08-01' },
  { id: 10050, parentId: null, name: 'Test2', type: 'mp4', size: 0, date: '2021-04-01' },
  { id: 24300, parentId: 10050, name: 'Test3', type: 'avi', size: 1024, date: '2020-03-01' },
  { id: 20045, parentId: 24300, name: 'test abc4', type: 'html', size: 600, date: '2021-04-01' },
  { id: 10053, parentId: 24300, name: 'test abc96', type: 'avi', size: 0, date: '2021-04-01' },
  { id: 24330, parentId: 10053, name: 'test abc5', type: 'txt', size: 25, date: '2021-10-01' },
  { id: 21011, parentId: 10053, name: 'Test6', type: 'pdf', size: 512, date: '2020-01-01' },
  { id: 22200, parentId: 10053, name: 'Test7', type: 'js', size: 1024, date: '2021-06-01' },
  { id: 23666, parentId: null, name: 'Test8', type: 'xlsx', size: 2048, date: '2020-11-01' },
  { id: 23677, parentId: 23666, name: 'Test7', type: 'js', size: 1024, date: '2021-06-01' },
  { id: 23671, parentId: 23677, name: 'Test7', type: 'js', size: 1024, date: '2021-06-01' },
  { id: 23672, parentId: 23677, name: 'Test7', type: 'js', size: 1024, date: '2021-06-01' },
  { id: 23688, parentId: 23666, name: 'Test7', type: 'js', size: 1024, date: '2021-06-01' },
  { id: 23681, parentId: 23688, name: 'Test7', type: 'js', size: 1024, date: '2021-06-01' },
  { id: 23682, parentId: 23688, name: 'Test7', type: 'js', size: 1024, date: '2021-06-01' },
  { id: 24555, parentId: null, name: 'test abc9', type: 'avi', size: 224, date: '2020-10-01' },
  { id: 24566, parentId: 24555, name: 'Test7', type: 'js', size: 1024, date: '2021-06-01' },
  { id: 24577, parentId: 24555, name: 'Test7', type: 'js', size: 1024, date: '2021-06-01' }
])

const selectChangeEvent: VxeTableEvents.CheckboxChange<RowVO> = () => {
  const $table = tableRef.value
  if ($table) {
    const records = $table.getCheckboxRecords()
    console.info(`勾选${records.length}个树形节点`, records)
  }
}
</script>

期望的结果:

No response

操作系统:

浏览器版本:

vue 版本:

vxe-pc-ui 版本:

vxe-table 版本:

是否使用当前最新版本?