Skip to content

Commit

Permalink
fix 修复复选框勾选无效问题 #2601
Browse files Browse the repository at this point in the history
  • Loading branch information
xuliangzhan committed Oct 16, 2024
1 parent 154de68 commit 4e4fa2a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 71 deletions.
105 changes: 36 additions & 69 deletions examples/views/table/TableTest9.vue
Original file line number Diff line number Diff line change
@@ -1,81 +1,48 @@
<template>
<div>
<vxe-button @click="scrollCol">滚动列</vxe-button>
<vxe-table
border
ref="tableRef"
height="400"
:data="tableData">
<vxe-colgroup title="基本信息" fixed="left">
<vxe-column type="seq" width="70" fixed="left"></vxe-column>
<vxe-column field="name" title="Name" fixed="left" width="180"></vxe-column>
</vxe-colgroup>
<vxe-colgroup title="更多信息">
<vxe-column field="role" title="Role" width="300"></vxe-column>
<vxe-column field="age" title="Age" width="200"></vxe-column>
<vxe-colgroup title="详细信息">
<vxe-column field="sex" title="Sex" width="200"></vxe-column>
<vxe-column field="num" title="Num" width="260"></vxe-column>
<vxe-column field="num11" title="Num11" width="200"></vxe-column>
<vxe-column field="num22" title="Num22" width="250"></vxe-column>
<vxe-column field="num33" title="Num33" width="100"></vxe-column>
<vxe-column field="num44" title="Num44" width="180"></vxe-column>
<vxe-column field="num55" title="Num55" width="260"></vxe-column>
<vxe-column field="num66" title="Num66" width="360"></vxe-column>
</vxe-colgroup>
</vxe-colgroup>
<vxe-column field="num77" title="Num77" width="260"></vxe-column>
<vxe-column field="num88" title="Num88" width="260"></vxe-column>
<vxe-colgroup title="额外信息" fixed="right">
<vxe-column field="date3" title="Date" fixed="right" width="140"></vxe-column>
<vxe-column field="address" title="Address" fixed="right" width="200" show-overflow></vxe-column>
</vxe-colgroup>
</vxe-table>
</div>
<div>树形表格</div>
<vxe-table
ref="tableRef1"
:tree-config="{ rowField: 'id' }"
:checkbox-config="{ labelField: 'id' }"
:data="tableData1"
>
<vxe-column type="checkbox" field="id" title="id" tree-node></vxe-column>
</vxe-table>
<button @click="selectRow1">选中第一行(有bug)</button>

<div>非树形表格</div>
<vxe-table
ref="tableRef2"
:checkbox-config="{ labelField: 'id' }"
:data="tableData2"
>
<vxe-column type="checkbox" field="id" title="id"></vxe-column>
</vxe-table>
<button @click="selectRow2">选中第一行(可以正常工作)</button>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import type { VxeTableInstance } from '../../../types'
interface RowVO {
id: number
name: string
role: string
sex: string
age: number
address: string
}
const tableRef1 = ref()
const tableRef = ref<VxeTableInstance>()
const selectRow1 = () => {
tableRef1.value.setCheckboxRow([tableData1.value[0]], true)
}
const tableData = ref<RowVO[]>([
{ id: 10001, name: 'Test1', role: 'Develop', sex: 'Man', age: 28, address: 'test abc' },
{ id: 10002, name: 'Test2', role: 'Test', sex: 'Women', age: 22, address: 'Guangzhou' },
{ id: 10003, name: 'Test3', role: 'PM', sex: 'Man', age: 32, address: 'Shanghai' },
{ id: 10004, name: 'Test4', role: 'Designer', sex: 'Women', age: 23, address: 'test abc' },
{ id: 10005, name: 'Test5', role: 'Develop', sex: 'Women', age: 30, address: 'Shanghai' },
{ id: 10006, name: 'Test6', role: 'Designer', sex: 'Women', age: 21, address: 'test abc' },
{ id: 10007, name: 'Test7', role: 'Test', sex: 'Man', age: 29, address: 'test abc' },
{ id: 10008, name: 'Test8', role: 'Develop', sex: 'Man', age: 35, address: 'test abc' },
{ id: 10009, name: 'Test9', role: 'Test', sex: 'Man', age: 26, address: 'test abc' },
{ id: 10010, name: 'Test10', role: 'Develop', sex: 'Man', age: 38, address: 'test abc' },
{ id: 10011, name: 'Test11', role: 'Test', sex: 'Women', age: 29, address: 'test abc' },
{ id: 10012, name: 'Test12', role: 'Develop', sex: 'Man', age: 27, address: 'test abc' },
{ id: 10013, name: 'Test13', role: 'Test', sex: 'Women', age: 24, address: 'test abc' },
{ id: 10014, name: 'Test14', role: 'Develop', sex: 'Man', age: 34, address: 'test abc' },
{ id: 10015, name: 'Test15', role: 'Test', sex: 'Man', age: 21, address: 'test abc' },
{ id: 10016, name: 'Test16', role: 'Develop', sex: 'Women', age: 20, address: 'test abc' },
{ id: 10017, name: 'Test17', role: 'Test', sex: 'Man', age: 31, address: 'test abc' },
{ id: 10018, name: 'Test18', role: 'Develop', sex: 'Women', age: 32, address: 'test abc' },
{ id: 10019, name: 'Test19', role: 'Test', sex: 'Man', age: 37, address: 'test abc' },
{ id: 10020, name: 'Test20', role: 'Develop', sex: 'Man', age: 41, address: 'test abc' }
const tableData1 = ref([
{ id: 10000 },
{ id: 10050, children: [{ id: 24300, children: [{ id: 20045 }] }] }
])
const scrollCol = () => {
const $table = tableRef.value
if ($table) {
$table.scrollToColumn('num33')
}
const tableRef2 = ref()
const selectRow2 = () => {
tableRef2.value.setCheckboxRow([tableData2.value[0]], true)
}
const tableData2 = ref([
{ id: 10000 },
{ id: 10050, children: [{ id: 24300, children: [{ id: 20045 }] }] }
])
</script>
4 changes: 2 additions & 2 deletions packages/table/src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5732,7 +5732,6 @@ export default defineComponent({
handleBatchSelectRows (rows, value, isForce) {
const { treeConfig } = props
const { selectCheckboxMaps } = reactData
const selectRowMaps = Object.assign({}, selectCheckboxMaps)
const checkboxOpts = computeCheckboxOpts.value
const { checkField, checkStrictly, checkMethod } = checkboxOpts
if (checkField) {
Expand All @@ -5754,6 +5753,7 @@ export default defineComponent({
tablePrivateMethods.handleSelectRow({ row }, value, isForce)
})
} else {
const selectRowMaps = Object.assign({}, selectCheckboxMaps)
rows.forEach(row => {
const rowid = getRowid($xeTable, row)
if (isForce || (!checkMethod || checkMethod({ row }))) {
Expand All @@ -5769,9 +5769,9 @@ export default defineComponent({
handleCheckboxReserveRow(row, value)
}
})
reactData.selectCheckboxMaps = selectRowMaps
}
}
reactData.selectCheckboxMaps = selectRowMaps
},
/**
* 单行
Expand Down

0 comments on commit 4e4fa2a

Please sign in to comment.