mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 19:19:57 +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,
|
multiple: boolean,
|
||||||
) {
|
) {
|
||||||
return filters.map((filter, index) => {
|
return filters.map((filter, index) => {
|
||||||
|
const key = String(filter.value);
|
||||||
|
|
||||||
if (filter.children) {
|
if (filter.children) {
|
||||||
return (
|
return (
|
||||||
<SubMenu
|
<SubMenu
|
||||||
key={filter.value || index}
|
key={key || index}
|
||||||
title={filter.text}
|
title={filter.text}
|
||||||
popupClassName={`${prefixCls}-dropdown-submenu`}
|
popupClassName={`${prefixCls}-dropdown-submenu`}
|
||||||
>
|
>
|
||||||
@ -38,8 +40,8 @@ function renderFilterItems(
|
|||||||
const Component = multiple ? Checkbox : Radio;
|
const Component = multiple ? Checkbox : Radio;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MenuItem key={filter.value !== undefined ? filter.value : index}>
|
<MenuItem key={filter.value !== undefined ? key : index}>
|
||||||
<Component checked={filteredKeys.includes(String(filter.value))} />
|
<Component checked={filteredKeys.includes(key)} />
|
||||||
<span>{filter.text}</span>
|
<span>{filter.text}</span>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
);
|
);
|
||||||
@ -187,7 +189,12 @@ function FilterDropdown<RecordType>(props: FilterDropdownProps<RecordType>) {
|
|||||||
openKeys={openKeys}
|
openKeys={openKeys}
|
||||||
onOpenChange={onOpenChange}
|
onOpenChange={onOpenChange}
|
||||||
>
|
>
|
||||||
{renderFilterItems(column.filters || [], prefixCls, getFilteredKeysSync(), filterMultiple)}
|
{renderFilterItems(
|
||||||
|
column.filters || [],
|
||||||
|
prefixCls,
|
||||||
|
getFilteredKeysSync(),
|
||||||
|
filterMultiple,
|
||||||
|
)}
|
||||||
</Menu>
|
</Menu>
|
||||||
<div className={`${prefixCls}-dropdown-btns`}>
|
<div className={`${prefixCls}-dropdown-btns`}>
|
||||||
<a className={`${prefixCls}-dropdown-link confirm`} onClick={onConfirm}>
|
<a className={`${prefixCls}-dropdown-link confirm`} onClick={onConfirm}>
|
||||||
|
@ -125,7 +125,7 @@ function generateFilterInfo<RecordType>(filterStates: FilterState<RecordType>[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
function flattenKeys(filters?: ColumnFilterItem[]) {
|
function flattenKeys(filters?: ColumnFilterItem[]) {
|
||||||
let keys: Key[] = [];
|
let keys: (string | number | boolean)[] = [];
|
||||||
(filters || []).forEach(({ value, children }) => {
|
(filters || []).forEach(({ value, children }) => {
|
||||||
keys.push(value);
|
keys.push(value);
|
||||||
if (children) {
|
if (children) {
|
||||||
|
@ -31,7 +31,7 @@ export type CompareFn<T> = (a: T, b: T, sortOrder?: SortOrder) => number;
|
|||||||
|
|
||||||
export interface ColumnFilterItem {
|
export interface ColumnFilterItem {
|
||||||
text: React.ReactNode;
|
text: React.ReactNode;
|
||||||
value: string;
|
value: string | number | boolean;
|
||||||
children?: ColumnFilterItem[];
|
children?: ColumnFilterItem[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ export interface ColumnType<RecordType> extends RcColumnType<RecordType> {
|
|||||||
filteredValue?: Key[] | null;
|
filteredValue?: Key[] | null;
|
||||||
defaultFilteredValue?: Key[] | null;
|
defaultFilteredValue?: Key[] | null;
|
||||||
filterIcon?: React.ReactNode | ((filtered: boolean) => React.ReactNode);
|
filterIcon?: React.ReactNode | ((filtered: boolean) => React.ReactNode);
|
||||||
onFilter?: (value: any, record: RecordType) => boolean;
|
onFilter?: (value: string | number | boolean, record: RecordType) => boolean;
|
||||||
filterDropdownVisible?: boolean;
|
filterDropdownVisible?: boolean;
|
||||||
onFilterDropdownVisibleChange?: (visible: boolean) => void;
|
onFilterDropdownVisibleChange?: (visible: boolean) => void;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user