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:
Xudong Huang 2020-03-18 11:20:21 +08:00 committed by GitHub
parent 73afd36619
commit 8fb9db174d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 7 deletions

View File

@ -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}>

View File

@ -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) {

View File

@ -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;
}