support undefined remove filter icon (#22833)

This commit is contained in:
二货机器人 2020-04-01 22:19:32 +08:00 committed by GitHub
parent 3f8dbc500f
commit 9aa61b78e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -57,6 +57,18 @@ describe('Table.filter', () => {
return wrapper.find('BodyRow').map(row => row.props().record.name); return wrapper.find('BodyRow').map(row => row.props().record.name);
} }
it('not show filter icon when undefined', () => {
const noFilterColumn = { ...column, filters: undefined };
delete noFilterColumn.onFilter;
const wrapper = mount(
createTable({
columns: [noFilterColumn],
}),
);
expect(wrapper.find('.ant-table-filter-column')).toHaveLength(0);
});
it('renders filter correctly', () => { it('renders filter correctly', () => {
const wrapper = mount(createTable()); const wrapper = mount(createTable());

View File

@ -31,7 +31,7 @@ function collectFilterStates<RecordType>(
if ('children' in column) { if ('children' in column) {
filterStates = [...filterStates, ...collectFilterStates(column.children, init, columnPos)]; filterStates = [...filterStates, ...collectFilterStates(column.children, init, columnPos)];
} else if ('filters' in column || 'filterDropdown' in column || 'onFilter' in column) { } else if (column.filters || 'filterDropdown' in column || 'onFilter' in column) {
if ('filteredValue' in column) { if ('filteredValue' in column) {
// Controlled // Controlled
filterStates.push({ filterStates.push({
@ -70,7 +70,7 @@ function injectFilter<RecordType>(
const columnPos = getColumnPos(index, pos); const columnPos = getColumnPos(index, pos);
const { filterMultiple = true } = column as ColumnType<RecordType>; const { filterMultiple = true } = column as ColumnType<RecordType>;
if ('filters' in column || 'filterDropdown' in column) { if (column.filters || 'filterDropdown' in column) {
const columnKey = getColumnKey(column, columnPos); const columnKey = getColumnKey(column, columnPos);
const filterState = filterStates.find(({ key }) => columnKey === key); const filterState = filterStates.find(({ key }) => columnKey === key);