Skip to content

Commit d7db0a3

Browse files
authored
fix: defaultExpandAllRows should work with childrenColumnName (#424)
1 parent d17efaa commit d7db0a3

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ env:
1515
matrix:
1616
- TEST_TYPE=lint
1717
- TEST_TYPE=test
18+
- TEST_TYPE=compile

src/Table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
272272
return defaultExpandedRowKeys;
273273
}
274274
if (defaultExpandAllRows) {
275-
return findAllChildrenKeys<RecordType>(mergedData, getRowKey);
275+
return findAllChildrenKeys<RecordType>(mergedData, getRowKey, mergedChildrenColumnName);
276276
}
277277
return [];
278278
});

src/utils/expandUtil.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ export function renderExpandIcon<RecordType>({
3434
export function findAllChildrenKeys<RecordType>(
3535
data: RecordType[],
3636
getRowKey: GetRowKey<RecordType>,
37+
childrenColumnName: string,
3738
): Key[] {
3839
const keys: Key[] = [];
3940

4041
function dig(list: RecordType[]) {
4142
(list || []).forEach((item, index) => {
4243
keys.push(getRowKey(item, index));
4344

44-
dig(((item as unknown) as { children: RecordType[] }).children);
45+
dig((item as any)[childrenColumnName]);
4546
});
4647
}
4748

tests/ExpandRow.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,4 +354,18 @@ describe('Table.Expand', () => {
354354
.hasClass('rc-table-row-collapsed'),
355355
).toBeTruthy();
356356
});
357+
358+
// https://github.com/ant-design/ant-design/issues/21788
359+
it('`defaultExpandAllRows` with `childrenColumnName`', () => {
360+
const data = [
361+
{
362+
key: 0,
363+
sub: [{ key: 1, sub: [{ key: 2 }] }],
364+
},
365+
];
366+
const wrapper = mount(
367+
createTable({ data, childrenColumnName: 'sub', expandable: { defaultExpandAllRows: true } }),
368+
);
369+
expect(wrapper.find('tbody tr')).toHaveLength(3);
370+
});
357371
});

0 commit comments

Comments
 (0)