mirror of
https://github.com/ant-design/ant-design.git
synced 2026-02-09 10:59:19 +08:00
Compare commits
2 Commits
theme
...
table-supp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57d266d967 | ||
|
|
d25784fbc8 |
@@ -60,10 +60,10 @@ import type {
|
||||
TablePaginationPosition,
|
||||
TableRowSelection,
|
||||
} from './interface';
|
||||
import TableMeasureRowContext from './TableMeasureRowContext';
|
||||
import RcTable from './RcTable';
|
||||
import RcVirtualTable from './RcTable/VirtualTable';
|
||||
import useStyle from './style';
|
||||
import TableMeasureRowContext from './TableMeasureRowContext';
|
||||
|
||||
export type { ColumnsType, TablePaginationConfig };
|
||||
|
||||
@@ -343,27 +343,6 @@ const InternalTable = <RecordType extends AnyObject = AnyObject>(
|
||||
nativeElement: rootRef.current!,
|
||||
}));
|
||||
|
||||
// ============================ RowKey ============================
|
||||
const rowKey = customizeRowKey || table?.rowKey || 'key';
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
warning(
|
||||
!(typeof rowKey === 'function' && rowKey.length > 1),
|
||||
'usage',
|
||||
'`index` parameter of `rowKey` function is deprecated. There is no guarantee that it will work as expected.',
|
||||
);
|
||||
}
|
||||
|
||||
const getRowKey = React.useMemo<GetRowKey<RecordType>>(() => {
|
||||
if (typeof rowKey === 'function') {
|
||||
return rowKey;
|
||||
}
|
||||
|
||||
return (record: RecordType) => record?.[rowKey as string];
|
||||
}, [rowKey]);
|
||||
|
||||
const [getRecordByKey] = useLazyKVMap(rawData, childrenColumnName, getRowKey);
|
||||
|
||||
// ============================ Events =============================
|
||||
const changeEventInfo: Partial<ChangeEventInfo<RecordType>> = {};
|
||||
|
||||
@@ -533,6 +512,35 @@ const InternalTable = <RecordType extends AnyObject = AnyObject>(
|
||||
mergedPagination?.total,
|
||||
]);
|
||||
|
||||
// ============================ RowKey ============================
|
||||
const rowKey = customizeRowKey || table?.rowKey || 'key';
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
warning(
|
||||
!(typeof rowKey === 'function' && rowKey.length > 1),
|
||||
'usage',
|
||||
'`index` parameter of `rowKey` function is deprecated. There is no guarantee that it will work as expected.',
|
||||
);
|
||||
}
|
||||
|
||||
const getRowKey = React.useMemo<GetRowKey<RecordType>>(() => {
|
||||
if (typeof rowKey === 'function') {
|
||||
return rowKey;
|
||||
}
|
||||
|
||||
return (record, index) => {
|
||||
if (typeof customizeRowKey === 'undefined') {
|
||||
if (mergedPagination) {
|
||||
return `${mergedPagination.current}-${index}`;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
return record?.[rowKey as string];
|
||||
};
|
||||
}, [rowKey, mergedPagination]);
|
||||
|
||||
const [getRecordByKey] = useLazyKVMap(rawData, childrenColumnName, getRowKey);
|
||||
|
||||
// ========================== Selections ==========================
|
||||
const [transformSelectionColumns, selectedKeySet] = useSelection<RecordType>(
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { TableColumnsType, TableProps } from 'antd';
|
||||
type TableRowSelection<T extends object = object> = TableProps<T>['rowSelection'];
|
||||
|
||||
interface DataType {
|
||||
key: React.Key;
|
||||
key?: React.Key;
|
||||
name: string;
|
||||
age: number;
|
||||
address: string;
|
||||
@@ -42,6 +42,7 @@ const App: React.FC = () => {
|
||||
};
|
||||
|
||||
const rowSelection: TableRowSelection<DataType> = {
|
||||
preserveSelectedRowKeys: true,
|
||||
selectedRowKeys,
|
||||
onChange: onSelectChange,
|
||||
selections: [
|
||||
@@ -79,7 +80,12 @@ const App: React.FC = () => {
|
||||
],
|
||||
};
|
||||
|
||||
return <Table<DataType> rowSelection={rowSelection} columns={columns} dataSource={dataSource} />;
|
||||
return (
|
||||
<>
|
||||
{JSON.stringify(selectedRowKeys)}
|
||||
<Table<DataType> rowSelection={rowSelection} columns={columns} dataSource={dataSource} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default App;
|
||||
|
||||
Reference in New Issue
Block a user