icflorescu / mantine-datatable

The table component for your Mantine data-rich applications, supporting asynchronous data loading, column sorting, custom cell data rendering, context menus, nesting, Gmail-style batch row selection, dark theme, and more.
https://icflorescu.github.io/mantine-datatable/
MIT License
866 stars 66 forks source link

Row expansion and nested table: nested row instead of nested tables #581

Open camdarley opened 2 months ago

camdarley commented 2 months ago

Is your feature request related to a problem? Please describe. When using the nested table feature, if the nested table data has the same type than the parent table, there is an issue with columns width not maching parent columns width, it's also not compatible with column resizing. Capture d’écran 2024-04-26 à 09 24 28 Of course we can use fixed columns width some issues, but it then adapt poorly to dynamic content.

Describe the solution you'd like Instead of adding an extra row with colspan and a new table inside, we could have an option to set new rows. We can't use collapse with table tr, but in this example we can see a way to animate toggling rows : https://stackoverflow.com/a/37376274 We could have an extra property to add new content "as rows":

return (
  <DataTable
    withTableBorder
    withColumnBorders
    columns={[{ accessor: 'name' }, { accessor: 'city' }, { accessor: 'state' }]}
    records={records}
    rowExpansion={{
      rows: [], // 👈 set this to add new "nested" rows
      // ...
    }}
  />
);

This could exists along with the content property to both add rows and nested content (and not breaking curent implementations)

mikkurogue commented 2 weeks ago

In a certain sense this is already "possible" through the content cb. At my work we have a similar use-case (just not styled very well because its for internal tooling).

We basically create a new Datatable as the return value of content and omit the header rendering to only render the rows. This is very dirty and hard to maintain, as it still requires the columns to be defined properly.

However I would also ask, how would you define a "nested" row? Is it an array of objects that stem from the main row itself or is it a separate object that populates by reference?

So would it be like

const items = [
    {
        name: "Hello",
        description: "Project Description",
        subProjects: [
            {
                name: "World",
                description: "Sub project description"
            }
        ]
    }
]

Or would it be split into 2 different objects and have a shared identifier to map the correct nested rows?