Tanstack Table grouping : Is it possible to disable grouping when there is only one row for the group?

431 Views Asked by At

I'm new at using Tanstack table by the use of Material React Table.

My dataset is a list of user with some infos (1st and 2nd rows) and 6th columns that defining a "Scope" object. So my users can have multiples "Scope" and I want to leverage MRT (aka Tanstack table) grouping to show that.

So I use aggregation to show the number of Scope when grouping Users.

I want to know if there is an option or a solution to prevent grouping when my user has only one Scope.

Here the picture when all groups are expanded (green = ok, red = change I want to made) : Screen of my current table

My code is pretty standard here but I can't find in the docs how to reach this use case ...

Thanks for your help ;)

What I tried before to ask for help >>> I just read the docs to figure out to disable grouping when there is only one row in the group. Don't find the answer.

1

There are 1 best solutions below

0
On

Finally, after hours of research I got it. Simply define getRowCanExpand props of the Material React Table

Here is the right doc : https://tanstack.com/table/v8/docs/api/features/expanding#getrowcanexpand

My custom condition, I don't want row with only one leaf (child) to be able to expand so :

getRowCanExpand={row => row.getLeafRows().length > 1}

I was misleading by searching "grouping" key word, it was "expand" the key. Sometimes difficult to understand well concept in English (not my native langage).

I hope it helps someone ;)