mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 14:13:37 +08:00
feat(Table): support onCell in rowSelection (#36187)
* feat: support onCell in rowSelection * fix: add onCell test * docs: update onCell related documentation * fix: format * fix: repeat import * Update More.tsx * fix: revert * fix: revert again * fix: revert again * fix: revert again * fix: revert again * Update index.zh-CN.md * Update index.en-US.md * Update index.zh-CN.md * Update index.en-US.md
This commit is contained in:
parent
8f6bf13b8c
commit
8215910cf7
@ -1218,6 +1218,19 @@ describe('Table.rowSelection', () => {
|
||||
expect(onChange.mock.calls[0][1]).toEqual([expect.objectContaining({ name: 'bamboo' })]);
|
||||
});
|
||||
|
||||
it('support onCell', () => {
|
||||
const onCell = jest.fn().mockReturnValue({ rowSpan: 4 });
|
||||
const { container } = render(
|
||||
createTable({
|
||||
rowSelection: {
|
||||
onCell,
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(onCell).toHaveBeenCalledTimes(8);
|
||||
expect(container.querySelectorAll("td[rowspan='4']").length).toBe(4);
|
||||
});
|
||||
|
||||
describe('supports children', () => {
|
||||
const dataWithChildren = [
|
||||
{ key: 0, name: 'Jack' },
|
||||
|
@ -13,10 +13,9 @@ import type { CheckboxProps } from '../../checkbox';
|
||||
import Checkbox from '../../checkbox';
|
||||
import Dropdown from '../../dropdown';
|
||||
import Radio from '../../radio';
|
||||
import type { AnyObject } from '../Table';
|
||||
import type {
|
||||
ColumnType,
|
||||
ColumnsType,
|
||||
ColumnType,
|
||||
ExpandType,
|
||||
GetPopupContainer,
|
||||
GetRowKey,
|
||||
@ -27,6 +26,7 @@ import type {
|
||||
TableRowSelection,
|
||||
TransformColumns,
|
||||
} from '../interface';
|
||||
import type { AnyObject } from '../Table';
|
||||
|
||||
// TODO: warning if use ajax!!!
|
||||
|
||||
@ -691,12 +691,15 @@ const useSelection = <RecordType extends AnyObject = any>(
|
||||
});
|
||||
|
||||
// Replace with real selection column
|
||||
const selectionColumn = {
|
||||
const selectionColumn: ColumnsType<RecordType>[0] & {
|
||||
RC_TABLE_INTERNAL_COL_DEFINE: Record<string, any>;
|
||||
} = {
|
||||
fixed: mergedFixed,
|
||||
width: selectionColWidth,
|
||||
className: `${prefixCls}-selection-column`,
|
||||
title: rowSelection.columnTitle || title,
|
||||
render: renderSelectionCell,
|
||||
onCell: rowSelection.onCell,
|
||||
[INTERNAL_COL_DEFINE]: { className: columnCls },
|
||||
};
|
||||
|
||||
|
@ -257,6 +257,7 @@ Properties for row selection.
|
||||
| selectedRowKeys | Controlled selected row keys | string\[] \| number\[] | \[] | |
|
||||
| selections | Custom selection [config](#selection), only displays default selections when set to `true` | object\[] \| boolean | - | |
|
||||
| type | `checkbox` or `radio` | `checkbox` \| `radio` | `checkbox` | |
|
||||
| onCell | Set props on per cell. Same as `onCell` in column | function(record, rowIndex) | - | 5.5.0 |
|
||||
| onChange | Callback executed when selected rows change | function(selectedRowKeys, selectedRows, info: { type }) | - | `info.type`: 4.21.0 |
|
||||
| onSelect | Callback executed when select/deselect one row | function(record, selected, selectedRows, nativeEvent) | - | |
|
||||
| onSelectAll | Callback executed when select/deselect all rows | function(selected, selectedRows, changeRows) | - | |
|
||||
|
@ -260,6 +260,7 @@ const columns = [
|
||||
| defaultSelectedRowKeys | 默认选中项的 key 数组 | string\[] \| number\[] | \[] | |
|
||||
| selections | 自定义选择项 [配置项](#selection), 设为 `true` 时使用默认选择项 | object\[] \| boolean | true | |
|
||||
| type | 多选/单选 | `checkbox` \| `radio` | `checkbox` | |
|
||||
| onCell | 设置单元格属性,用法与 Column 的 `onCell` 相同 | function(record, rowIndex) | - | 5.5.0 |
|
||||
| onChange | 选中项发生变化时的回调 | function(selectedRowKeys, selectedRows, info: { type }) | - | `info.type`: 4.21.0 |
|
||||
| onSelect | 用户手动选择/取消选择某行的回调 | function(record, selected, selectedRows, nativeEvent) | - | |
|
||||
| onSelectAll | 用户手动选择/取消选择所有行的回调 | function(selected, selectedRows, changeRows) | - | |
|
||||
|
@ -1,6 +1,7 @@
|
||||
import type {
|
||||
ColumnType as RcColumnType,
|
||||
FixedType,
|
||||
GetComponentProps,
|
||||
RenderedCell as RcRenderedCell,
|
||||
} from 'rc-table/lib/interface';
|
||||
import { ExpandableConfig, GetRowKey } from 'rc-table/lib/interface';
|
||||
@ -198,6 +199,7 @@ export interface TableRowSelection<T> {
|
||||
index: number,
|
||||
originNode: React.ReactNode,
|
||||
) => React.ReactNode | RcRenderedCell<T>;
|
||||
onCell?: GetComponentProps<T>;
|
||||
}
|
||||
|
||||
export type TransformColumns<RecordType> = (
|
||||
|
Loading…
Reference in New Issue
Block a user