Skip to content

Commit

Permalink
feat(comp:table): supports record for customCell of selectable column (
Browse files Browse the repository at this point in the history
  • Loading branch information
sallerli1 committed Sep 8, 2023
1 parent e8068bd commit b80ba68
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/components/table/docs/Api.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export type TableColumn<T = any, V = any> =
| `onSelectInvert` | 点击反选所有时触发 | `(selectedRowKeys: (string \| number)[]) => void` | - | - | 配置 `menus= ['invert']` 时生效 |
| `onSelectNone` | 点击清空所有时触发 | `() => void` | - | - | 配置 `menus= ['none']` 时生效 |
| `onSelectPageInvert` | 点击反选当页所有时触发 | `() => void` | - | - | 配置 `menus= ['pageInvert']` 时生效 |
| `customCell` | 自定义单元格内容 | `string \| ((data: { checked: boolean; disabled: boolean; indeterminate?: boolean, onChange: () => void, onClick: () => void }) => VNodeChild)` | - | - | 类型为 `string` 时,对应插槽名 |
| `customCell` | 自定义单元格内容 | `string \| ((data: { record: T; rowIndex: number; checked: boolean; disabled: boolean; indeterminate?: boolean, onChange: () => void, onClick: () => void }) => VNodeChild)` | - | - | 类型为 `string` 时,对应插槽名 |
#### TableColumnIndexable
Expand Down
10 changes: 7 additions & 3 deletions packages/components/table/src/main/body/BodyCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ function renderSelectableChildren(
config: TableConfig,
mergedPagination: ComputedRef<TablePagination | null>,
) {
const { selected: checked, indeterminate, disabled, isHover, handleSelect: onChange } = props
const { record, rowIndex, selected: checked, indeterminate, disabled, isHover, handleSelect: onChange } = props
const { showIndex, multiple, customCell } = selectable.value!
const onClick = (evt: Event) => {
// see https://github.com/IDuxFE/idux/issues/547
Expand All @@ -228,10 +228,14 @@ function renderSelectableChildren(
const customRender = isString(customCell) ? slots[customCell] : customCell
if (multiple) {
const checkboxProps = { checked, disabled, indeterminate, onChange, onClick }
return customRender ? customRender(checkboxProps) : <IxCheckbox {...checkboxProps}></IxCheckbox>
return customRender ? (
customRender({ ...checkboxProps, record, rowIndex })
) : (
<IxCheckbox {...checkboxProps}></IxCheckbox>
)
} else {
const radioProps = { checked, disabled, onChange, onClick }
return customRender ? customRender(radioProps) : <IxRadio {...radioProps}></IxRadio>
return customRender ? customRender({ ...radioProps, record, rowIndex }) : <IxRadio {...radioProps}></IxRadio>
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/components/table/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ export interface TableColumnSelectable<T = any, K = VKey> extends TableColumnCom
checked: boolean
disabled: boolean
indeterminate?: boolean
record: T
rowIndex: number
onChange: () => void
onClick: () => void
}) => VNodeChild)
Expand Down

0 comments on commit b80ba68

Please sign in to comment.