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, }; }, });