Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "expandable" property defining if row can be expanded #579

Closed
camdarley opened this issue Apr 25, 2024 · 7 comments
Closed

Add "expandable" property defining if row can be expanded #579

camdarley opened this issue Apr 25, 2024 · 7 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@camdarley
Copy link
Contributor

Is your feature request related to a problem? Please describe.
I would like to use the expansion feature with nested tables, to expand rows which have a children property.
For rows which don't have children, I would like to disable the expansion feature.

Describe the solution you'd like
Best would be to add a expandable prop, which is a function taking record and index as arguments, and returning a boolean defining wether or not the row is expandable.

<DataTable
      withTableBorder
      withColumnBorders
      columns={[{ accessor: 'name' }, { accessor: 'city' }, { accessor: 'state' }]}
      records={records}
      rowExpansion={{
        allowMultiple: true,
        expandable: ({ record }) => record.children && record.children.length > 0, // 👈 enable expansion only on rows which have children
        content: ({ record }) => (
        ...
@icflorescu icflorescu added enhancement New feature or request good first issue Good for newcomers labels Apr 25, 2024
@camdarley
Copy link
Contributor Author

#580

@icflorescu
Copy link
Owner

That's a good idea, thanks.
I'm up to my ears in a project at the moment, but I'll have a look at how this could be implemented when I'll find a moment.

@icflorescu
Copy link
Owner

Wow, that was fast! :-)

@camdarley
Copy link
Contributor Author

Actually I filled the issue while I was already working on the PR :-)

@icflorescu
Copy link
Owner

Thanks, I'll merge and publish it later today!

@camdarley
Copy link
Contributor Author

Great, thanks!
I just pushed a new commit with default behavior (when expandable prop is missing) set as "expandable", otherwise it would break existing code!

@icflorescu
Copy link
Owner

Released in v7.8.2 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants