mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 22:36:31 +08:00
parent
5217a4809c
commit
821ced5e30
@ -981,7 +981,7 @@ export default class Table<T> extends React.Component<TableProps<T>, TableState<
|
||||
}
|
||||
|
||||
getFlatData() {
|
||||
return flatArray(this.getLocalData());
|
||||
return flatArray(this.getLocalData(null, false));
|
||||
}
|
||||
|
||||
getFlatCurrentPageData() {
|
||||
@ -996,7 +996,7 @@ export default class Table<T> extends React.Component<TableProps<T>, TableState<
|
||||
} : item));
|
||||
}
|
||||
|
||||
getLocalData(state?: TableState<T>) {
|
||||
getLocalData(state?: TableState<T> | null, filter: boolean = true): Array<T> {
|
||||
const currentState: TableState<T> = state || this.state;
|
||||
const { dataSource } = this.props;
|
||||
let data = dataSource || [];
|
||||
@ -1007,7 +1007,7 @@ export default class Table<T> extends React.Component<TableProps<T>, TableState<
|
||||
data = this.recursiveSort(data, sorterFn);
|
||||
}
|
||||
// 筛选
|
||||
if (currentState.filters) {
|
||||
if (filter && currentState.filters) {
|
||||
Object.keys(currentState.filters).forEach((columnKey) => {
|
||||
const col = this.findColumn(columnKey) as any;
|
||||
if (!col) {
|
||||
|
@ -442,4 +442,61 @@ describe('Table.rowSelection', () => {
|
||||
});
|
||||
expect(wrapper.find('thead tr div').at(0).text()).toBe('单选');
|
||||
});
|
||||
|
||||
// https://github.com/ant-design/ant-design/issues/11384
|
||||
it('should keep item even if in filter', () => {
|
||||
const filterColumns = [{
|
||||
title: 'Name',
|
||||
dataIndex: 'name',
|
||||
filters: [{
|
||||
text: 'Jack',
|
||||
value: 'Jack',
|
||||
}, {
|
||||
text: 'Lucy',
|
||||
value: 'Lucy',
|
||||
}],
|
||||
filterDropdownVisible: true,
|
||||
onFilter: (value, record) => record.name.indexOf(value) === 0,
|
||||
}];
|
||||
|
||||
const onChange = jest.fn();
|
||||
const rowSelection = {
|
||||
onChange,
|
||||
};
|
||||
|
||||
const wrapper = mount(
|
||||
<Table
|
||||
columns={filterColumns}
|
||||
dataSource={data}
|
||||
rowSelection={rowSelection}
|
||||
/>
|
||||
);
|
||||
|
||||
function clickFilter(indexList) {
|
||||
indexList.forEach((index) => {
|
||||
wrapper.find('.ant-dropdown-menu-item .ant-checkbox-wrapper').at(index).simulate('click');
|
||||
});
|
||||
wrapper.find('.ant-table-filter-dropdown-btns .ant-table-filter-dropdown-link.confirm').simulate('click');
|
||||
}
|
||||
|
||||
function clickItem() {
|
||||
wrapper.find('tbody .ant-table-selection-column .ant-checkbox-input').at(0).simulate('change', {
|
||||
target: { checked: true },
|
||||
});
|
||||
}
|
||||
|
||||
// Check Jack
|
||||
clickFilter([0]);
|
||||
expect(wrapper.find('tbody tr').length).toBe(1);
|
||||
clickItem();
|
||||
expect(onChange.mock.calls[0][0].length).toBe(1);
|
||||
expect(onChange.mock.calls[0][1].length).toBe(1);
|
||||
|
||||
// Check Lucy
|
||||
clickFilter([0, 1]);
|
||||
expect(wrapper.find('tbody tr').length).toBe(1);
|
||||
clickItem();
|
||||
expect(onChange.mock.calls[1][0].length).toBe(2);
|
||||
expect(onChange.mock.calls[1][1].length).toBe(2);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user