|
@@ -839,36 +839,59 @@ class Table<RecordType extends Record<string, any>> extends BaseComponent<Normal
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
- renderSelection = (record = {} as any, inHeader = false): React.ReactNode => {
|
|
|
|
|
|
+ renderSelection = (record = {} as any, inHeader = false, index?: number): React.ReactNode => {
|
|
const { rowSelection, allDisabledRowKeysSet } = this.state;
|
|
const { rowSelection, allDisabledRowKeysSet } = this.state;
|
|
|
|
|
|
if (rowSelection && typeof rowSelection === 'object') {
|
|
if (rowSelection && typeof rowSelection === 'object') {
|
|
- const { selectedRowKeys = [], selectedRowKeysSet = new Set(), getCheckboxProps, disabled } = rowSelection;
|
|
|
|
|
|
+ const {
|
|
|
|
+ selectedRowKeys = [],
|
|
|
|
+ selectedRowKeysSet = new Set(),
|
|
|
|
+ getCheckboxProps,
|
|
|
|
+ disabled,
|
|
|
|
+ renderCell,
|
|
|
|
+ } = rowSelection;
|
|
|
|
+
|
|
|
|
+ const allRowKeys = this.cachedFilteredSortedRowKeys;
|
|
|
|
+ const allRowKeysSet = this.cachedFilteredSortedRowKeysSet;
|
|
|
|
+ const allIsSelected = this.foundation.allIsSelected(selectedRowKeysSet, allDisabledRowKeysSet, allRowKeys);
|
|
|
|
+ const hasRowSelected = this.foundation.hasRowSelected(selectedRowKeys, allRowKeysSet);
|
|
|
|
+ const indeterminate = hasRowSelected && !allIsSelected;
|
|
|
|
|
|
if (inHeader) {
|
|
if (inHeader) {
|
|
const columnKey = get(rowSelection, 'key', strings.DEFAULT_KEY_COLUMN_SELECTION);
|
|
const columnKey = get(rowSelection, 'key', strings.DEFAULT_KEY_COLUMN_SELECTION);
|
|
- const allRowKeys = this.cachedFilteredSortedRowKeys;
|
|
|
|
- const allRowKeysSet = this.cachedFilteredSortedRowKeysSet;
|
|
|
|
- const allIsSelected = this.foundation.allIsSelected(selectedRowKeysSet, allDisabledRowKeysSet, allRowKeys);
|
|
|
|
- const hasRowSelected = this.foundation.hasRowSelected(selectedRowKeys, allRowKeysSet);
|
|
|
|
- return (
|
|
|
|
|
|
+
|
|
|
|
+ const originNode = (
|
|
<ColumnSelection
|
|
<ColumnSelection
|
|
aria-label={`${allIsSelected ? 'Deselect' : 'Select'} all rows`}
|
|
aria-label={`${allIsSelected ? 'Deselect' : 'Select'} all rows`}
|
|
disabled={disabled}
|
|
disabled={disabled}
|
|
key={columnKey}
|
|
key={columnKey}
|
|
selected={allIsSelected}
|
|
selected={allIsSelected}
|
|
- indeterminate={hasRowSelected && !allIsSelected}
|
|
|
|
|
|
+ indeterminate={indeterminate}
|
|
onChange={(selected, e) => {
|
|
onChange={(selected, e) => {
|
|
this.toggleSelectAllRow(selected, e);
|
|
this.toggleSelectAllRow(selected, e);
|
|
}}
|
|
}}
|
|
/>
|
|
/>
|
|
);
|
|
);
|
|
|
|
+
|
|
|
|
+ const selectAll = (selected: boolean, e: Event) =>
|
|
|
|
+ this.toggleSelectAllRow(selected, e as TableSelectionCellEvent);
|
|
|
|
+
|
|
|
|
+ return isFunction(renderCell)
|
|
|
|
+ ? renderCell({
|
|
|
|
+ selected: allIsSelected,
|
|
|
|
+ record,
|
|
|
|
+ originNode,
|
|
|
|
+ inHeader,
|
|
|
|
+ disabled,
|
|
|
|
+ indeterminate,
|
|
|
|
+ selectAll,
|
|
|
|
+ })
|
|
|
|
+ : originNode;
|
|
} else {
|
|
} else {
|
|
const key = this.foundation.getRecordKey(record);
|
|
const key = this.foundation.getRecordKey(record);
|
|
const selected = selectedRowKeysSet.has(key);
|
|
const selected = selectedRowKeysSet.has(key);
|
|
const checkboxPropsFn = () => (typeof getCheckboxProps === 'function' ? getCheckboxProps(record) : {});
|
|
const checkboxPropsFn = () => (typeof getCheckboxProps === 'function' ? getCheckboxProps(record) : {});
|
|
-
|
|
|
|
- return (
|
|
|
|
|
|
+ const originNode = (
|
|
<ColumnSelection
|
|
<ColumnSelection
|
|
aria-label={`${selected ? 'Deselect' : 'Select'} this row`}
|
|
aria-label={`${selected ? 'Deselect' : 'Select'} this row`}
|
|
getCheckboxProps={checkboxPropsFn}
|
|
getCheckboxProps={checkboxPropsFn}
|
|
@@ -876,13 +899,28 @@ class Table<RecordType extends Record<string, any>> extends BaseComponent<Normal
|
|
onChange={(status, e) => this.toggleSelectRow(status, key, e)}
|
|
onChange={(status, e) => this.toggleSelectRow(status, key, e)}
|
|
/>
|
|
/>
|
|
);
|
|
);
|
|
|
|
+ const selectRow = (selected: boolean, e: Event) =>
|
|
|
|
+ this.toggleSelectRow(selected, key, e as TableSelectionCellEvent);
|
|
|
|
+
|
|
|
|
+ return isFunction(renderCell)
|
|
|
|
+ ? renderCell({
|
|
|
|
+ selected,
|
|
|
|
+ record,
|
|
|
|
+ index,
|
|
|
|
+ originNode,
|
|
|
|
+ inHeader: false,
|
|
|
|
+ disabled,
|
|
|
|
+ indeterminate,
|
|
|
|
+ selectRow,
|
|
|
|
+ })
|
|
|
|
+ : originNode;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
};
|
|
};
|
|
|
|
|
|
- renderRowSelectionCallback = (text: string, record: RecordType = {} as RecordType) => this.renderSelection(record);
|
|
|
|
- renderTitleSelectionCallback = () => this.renderSelection(null, true);
|
|
|
|
|
|
+ renderRowSelectionCallback = (text: string, record: RecordType = {} as RecordType, index: number) => this.renderSelection(record, false, index);
|
|
|
|
+ renderTitleSelectionCallback = () => this.renderSelection(undefined, true);
|
|
|
|
|
|
normalizeSelectionColumn = (props: { rowSelection?: TableStateRowSelection<RecordType>; prefixCls?: string } = {}) => {
|
|
normalizeSelectionColumn = (props: { rowSelection?: TableStateRowSelection<RecordType>; prefixCls?: string } = {}) => {
|
|
const { rowSelection, prefixCls } = props;
|
|
const { rowSelection, prefixCls } = props;
|