react-component / react-component/table

rowExpandable does not work when dataSource has children field

Open
#1,416 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1.4k
Forks
618
Avg merge
10h 19m
Merged PRs (30d)
2

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Table entry point and trace how expandable.rowExpandable is handled when records include children. Reproduce the example with one populated and one empty children array, then verify that only the first row shows an expand icon and that rowExpandable is invoked in tree mode.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.