mantine-datatable icon indicating copy to clipboard operation
mantine-datatable copied to clipboard

rowExpansion bug: All rows expand

Open ndanny opened this issue 4 years ago • 2 comments

Describe the bug In the rowExpansion feature...

If any/all records have a field name that starts with a capital letter, clicking on any row causes all rows to expand.

For instance: const rows = [{ID: 123, "First Name": "Danny"}, {ID: 789, "First Name": "Eiter"}] causes all records to expand instead of the single row the user clicks.

A temporary workaround is to do the following: const rows = [{id: 123, firstName: "Danny"}, {id: 789, firstName: "Eiter"}]

To Reproduce Steps to reproduce the behavior:

  1. Create a DataTable using the rows example I showed above.
  2. In the UI, expand the first row.
  3. All rows will expand.

Expected behavior Only one row should expand.

Screenshots N/A

Desktop (please complete the following information):

  • OS: macOS
  • Browser Chrome
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context TypeScript, NextJS

ndanny avatar Oct 13 '22 21:10 ndanny

That's awkward :-) Well spotted, thanks. Will have a look and let you know as soon as it's fixed.

icflorescu avatar Oct 14 '22 09:10 icflorescu

Your example almost got me fooled as well, but no, it's actually not a bug. and has nothing to do with capital letter columns.

It's easy to miss, but if you're using const rows = [{ID: 123, "First Name": "Danny"}, {ID: 789, "First Name": "Eiter"}] as a data source, it means you have a non-standard record id. The default idAccessor is 'id', and 'ID' !== 'id'.

So, if you want to keep your data source as it is, set the DataTable idAccessor to 'ID' like so:

<DataTable
  columns={[{ accessor: 'ID' }, { accessor: 'First Name' }]}
  records={[
    { ID: 123, 'First Name': 'Danny' },
    { ID: 789, 'First Name': 'Eiter' },
  ]}
  idAccessor="ID" // 👉 because 'ID' !== 'id'
  rowExpansion={{ content: () => <Box p="lg">Expanded</Box> }}
/>

icflorescu avatar Oct 14 '22 10:10 icflorescu