table icon indicating copy to clipboard operation
table copied to clipboard

rowExpandable does not work when dataSource has children field

Open fengwuxp opened this issue 2 months ago • 0 comments

Description When using rc-table with tree data structure (when dataSource contains children field), the rowExpandable configuration is completely ignored. This prevents developers from controlling which rows should be expandable based on custom logic.

Current Behavior When dataSource contains children field, the table automatically enables tree mode

In tree mode, the presence of children field alone determines expandability, regardless of its content

Empty children arrays ([]) still show expand icons

The rowExpandable function is never called or its return value is ignored

Expected Behavior rowExpandable should work consistently regardless of whether the table is in tree mode or not

Developers should be able to control expandability using custom logic even when children field exists

When rowExpandable returns false for a row, it should not show expand icon regardless of children field

import { Table } from 'rc-table';

const dataSource = [
  {
    key: '1',
    name: 'Parent 1',
    children: [
      { key: '1-1', name: 'Child 1-1' },
    ],
  },
  {
    key: '2',
    name: 'Parent 2',
    children: [], // Empty children - should not be expandable
  },
];

const columns = [
  {
    title: 'Name',
    dataIndex: 'name',
    key: 'name',
  },
];

const App = () => (
  <Table
    dataSource={dataSource}
    columns={columns}
    expandable={{
      // This is ignored because children field exists
      rowExpandable: (record) => 
        record.children && record.children.length > 0
    }}
  />
);

In this example, both rows show expand icons, but the second row should not be expandable since its children array is empty.

fengwuxp avatar Nov 20 '25 07:11 fengwuxp