fix: Table onFilter only should work (#22317)

* adjust table logic

* test case
This commit is contained in:
二货机器人 2020-03-17 21:50:01 +08:00 committed by GitHub
parent 8fa2252903
commit f4d3dc4306
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -1213,4 +1213,14 @@ describe('Table.filter', () => {
expect(wrapper.find('.ant-table-filter-trigger').hasClass('active')).toBeTruthy();
});
it('with onFilter', () => {
const onFilter = jest.fn((value, record) => record.key === value);
const columns = [{ dataIndex: 'key', filteredValue: [5], onFilter }];
const testData = [{ key: 1 }, { key: 3 }, { key: 5 }];
const wrapper = mount(<Table columns={columns} dataSource={testData} />);
expect(onFilter).toHaveBeenCalled();
expect(wrapper.find('tbody tr')).toHaveLength(1);
});
});

View File

@ -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) {
} else if ('filters' in column || 'filterDropdown' in column || 'onFilter' in column) {
if ('filteredValue' in column) {
// Controlled
filterStates.push({