mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 13:09:40 +08:00
fix: Table column filter value type could be any (#22277)
* fix: Table column filter value type could be any * Update components/table/interface.tsx Co-Authored-By: 偏右 <afc163@gmail.com> * fix: Solve modification type failed CI check Co-authored-by: 偏右 <afc163@gmail.com>
This commit is contained in:
parent
73afd36619
commit
8fb9db174d
@ -23,10 +23,12 @@ function renderFilterItems(
|
||||
multiple: boolean,
|
||||
) {
|
||||
return filters.map((filter, index) => {
|
||||
const key = String(filter.value);
|
||||
|
||||
if (filter.children) {
|
||||
return (
|
||||
<SubMenu
|
||||
key={filter.value || index}
|
||||
key={key || index}
|
||||
title={filter.text}
|
||||
popupClassName={`${prefixCls}-dropdown-submenu`}
|
||||
>
|
||||
@ -38,8 +40,8 @@ function renderFilterItems(
|
||||
const Component = multiple ? Checkbox : Radio;
|
||||
|
||||
return (
|
||||
<MenuItem key={filter.value !== undefined ? filter.value : index}>
|
||||
<Component checked={filteredKeys.includes(String(filter.value))} />
|
||||
<MenuItem key={filter.value !== undefined ? key : index}>
|
||||
<Component checked={filteredKeys.includes(key)} />
|
||||
<span>{filter.text}</span>
|
||||
</MenuItem>
|
||||
);
|
||||
@ -187,7 +189,12 @@ function FilterDropdown<RecordType>(props: FilterDropdownProps<RecordType>) {
|
||||
openKeys={openKeys}
|
||||
onOpenChange={onOpenChange}
|
||||
>
|
||||
{renderFilterItems(column.filters || [], prefixCls, getFilteredKeysSync(), filterMultiple)}
|
||||
{renderFilterItems(
|
||||
column.filters || [],
|
||||
prefixCls,
|
||||
getFilteredKeysSync(),
|
||||
filterMultiple,
|
||||
)}
|
||||
</Menu>
|
||||
<div className={`${prefixCls}-dropdown-btns`}>
|
||||
<a className={`${prefixCls}-dropdown-link confirm`} onClick={onConfirm}>
|
||||
|
@ -125,7 +125,7 @@ function generateFilterInfo<RecordType>(filterStates: FilterState<RecordType>[])
|
||||
}
|
||||
|
||||
function flattenKeys(filters?: ColumnFilterItem[]) {
|
||||
let keys: Key[] = [];
|
||||
let keys: (string | number | boolean)[] = [];
|
||||
(filters || []).forEach(({ value, children }) => {
|
||||
keys.push(value);
|
||||
if (children) {
|
||||
|
@ -31,7 +31,7 @@ export type CompareFn<T> = (a: T, b: T, sortOrder?: SortOrder) => number;
|
||||
|
||||
export interface ColumnFilterItem {
|
||||
text: React.ReactNode;
|
||||
value: string;
|
||||
value: string | number | boolean;
|
||||
children?: ColumnFilterItem[];
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ export interface ColumnType<RecordType> extends RcColumnType<RecordType> {
|
||||
filteredValue?: Key[] | null;
|
||||
defaultFilteredValue?: Key[] | null;
|
||||
filterIcon?: React.ReactNode | ((filtered: boolean) => React.ReactNode);
|
||||
onFilter?: (value: any, record: RecordType) => boolean;
|
||||
onFilter?: (value: string | number | boolean, record: RecordType) => boolean;
|
||||
filterDropdownVisible?: boolean;
|
||||
onFilterDropdownVisibleChange?: (visible: boolean) => void;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user