Browse Source

support undefined remove filter icon (#22833)

pull/22836/head
二货机器人 5 years ago
committed by GitHub
parent
commit
9aa61b78e1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      components/table/__tests__/Table.filter.test.js
  2. 4
      components/table/hooks/useFilter/index.tsx

12
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());

4
components/table/hooks/useFilter/index.tsx

@ -31,7 +31,7 @@ function collectFilterStates<RecordType>(
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<RecordType>(
const columnPos = getColumnPos(index, pos);
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 filterState = filterStates.find(({ key }) => columnKey === key);

Loading…
Cancel
Save