From 5335ae7578f9c06b05c4f96d66f08dfecaaf1cf6 Mon Sep 17 00:00:00 2001 From: luojz <74349832+coderluojz@users.noreply.github.com> Date: Wed, 22 Feb 2023 18:32:32 +0800 Subject: [PATCH] fix(FormTable): fix table spread selection(#2565) (#2574) Co-authored-by: luojingzhou --- src/views/demo/table/FormTable.vue | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/views/demo/table/FormTable.vue b/src/views/demo/table/FormTable.vue index fc565edfe..beaf151f3 100644 --- a/src/views/demo/table/FormTable.vue +++ b/src/views/demo/table/FormTable.vue @@ -44,7 +44,8 @@ rowSelection: { type: 'checkbox', selectedRowKeys: checkedKeys, - onChange: onSelectChange, + onSelect: onSelect, + onSelectAll: onSelectAll, }, }); @@ -52,16 +53,30 @@ console.log(getForm().getFieldsValue()); } - function onSelectChange(selectedRowKeys: (string | number)[]) { - console.log(selectedRowKeys); - checkedKeys.value = selectedRowKeys; + function onSelect(record, selected) { + if (selected) { + checkedKeys.value = [...checkedKeys.value, record.id]; + } else { + checkedKeys.value = checkedKeys.value.filter((id) => id !== record.id); + } + } + function onSelectAll(selected, selectedRows, changeRows) { + const changeIds = changeRows.map((item) => item.id); + if (selected) { + checkedKeys.value = [...checkedKeys.value, ...changeIds]; + } else { + checkedKeys.value = checkedKeys.value.filter((id) => { + return !changeIds.includes(id); + }); + } } return { registerTable, getFormValues, checkedKeys, - onSelectChange, + onSelect, + onSelectAll, }; }, });