Skip to content

Commit

Permalink
feat: 添加全选时数组回调
Browse files Browse the repository at this point in the history
  • Loading branch information
Flcwl committed Nov 10, 2021
1 parent 6723ce7 commit 7066cd3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions components/table/HeaderTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,14 @@ const HeaderTable = ({ rightFixedIndex }) => {
indeterminate={!isAllChecked && rowSelection.selectedRowKeys.length > 0}
onChange={(e) => {
if (rowSelection.onChange) {
const selectedItems = isAllChecked
? []
: flatTreeData(_.cloneDeep(data)).filter((data) => !disabledData.current.includes(data.key))

rowSelection.onChange(
isAllChecked
? []
: flatTreeData(_.cloneDeep(data))
.filter((data) => !disabledData.current.includes(data.key))
.map((d) => d.key)
selectedItems.map((item) => item.key),
selectedItems,
!isAllChecked
)
}
}}
Expand Down
2 changes: 1 addition & 1 deletion components/table/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type TableFixedOption = {
export type TableRowSelection = {
selectedRowKeys?: string[] | number[]
getCheckboxConfig?: (rowData: object) => object
onChange?: (selectedRowKeys: string | number, targetRow?: object, shouldChecked?: boolean) => void
onChange?: (selectedRowKeys: string | number, targetRow?: object | object[], shouldChecked?: boolean) => void
}

export type TableHeaderRowReturn = {
Expand Down
2 changes: 1 addition & 1 deletion docs/zh-CN/components/table.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,4 @@ import DemoAsync from '../../demo/table/section-async.jsx'
| ----------------- | ---------------------- | ----------------------------------- | ---------------- | ------ |
| selectedRowKeys | 选中的行(受控) | string[] | row 中对应的 key | - |
| getCheckboxConfig | 行选择的配置项 | rowData => object | - | - |
| onChange | 选中项发生变化时的回调,如果是全选操作,targetRow 和 shouldChecked 为 undefined | (selectedRowKeys: string[], targetRow?: object, shouldChecked?: boolean ) => void | - | - |
| onChange | 选中项发生变化时的回调,如果是全选操作,`targetRow` 将是数组结构 | (selectedRowKeys: string[], targetRow?: object \| object[], shouldChecked?: boolean) => void | - | - |

0 comments on commit 7066cd3

Please sign in to comment.