diff --git a/components/table/__tests__/Table.filter.test.js b/components/table/__tests__/Table.filter.test.js index bd5b772d8f..b08a863e10 100644 --- a/components/table/__tests__/Table.filter.test.js +++ b/components/table/__tests__/Table.filter.test.js @@ -57,6 +57,18 @@ describe('Table.filter', () => { 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', () => { const wrapper = mount(createTable()); diff --git a/components/table/hooks/useFilter/index.tsx b/components/table/hooks/useFilter/index.tsx index 7ff606a3a4..f56cf42c8f 100644 --- a/components/table/hooks/useFilter/index.tsx +++ b/components/table/hooks/useFilter/index.tsx @@ -31,7 +31,7 @@ function collectFilterStates( if ('children' in column) { 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) { // Controlled filterStates.push({ @@ -70,7 +70,7 @@ function injectFilter( const columnPos = getColumnPos(index, pos); const { filterMultiple = true } = column as ColumnType; - if ('filters' in column || 'filterDropdown' in column) { + if (column.filters || 'filterDropdown' in column) { const columnKey = getColumnKey(column, columnPos); const filterState = filterStates.find(({ key }) => columnKey === key);