How to group rows only if there is more than one sub-row #2775
-
I am stumped on a question about grouping rows when some of the source data has "groups" of one. I am putting together tables that show sports statistics for a player, like in this example: As you can see, there are records with just one row for a given year (like 2018), or there may be multiple rows with the same year (like 2019), where a player was on more than one team. I have set up a table with groupBy 'year', and have used the toggleAllRowsExpanded prop to have all rows expanded on the table by default (the approach I used is the same as described in #2404). But this ends up showing expanded groups not only for rows with multiple sub-rows, but also rows with only one "sub" row. It looks like this: I have a feeling I'm going about this the wrong way, but I'm wondering--is there a way to only "group" rows if the group size is greater than one? (Another way of putting this, since I have a suspicion I'm sniffing around something pretty straightforward but I'm not coming up with the right term for it--is it possible to NOT aggregate rows if there is only one child row of the grouped value?) Thanks for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I came up with a solution, maybe it's not the best way, but it seems to work fine so far. What I do is, when rendering the table rows, make a check whether the current row has only one subRow. If it does, don't render; if it doesn't, render as normal. Like so: {rows.map((row, i) => {
if (row.subRows.length === 1) {
return null
}
else {
prepareRow(row)
return (
[render table row]
)
}
})} |
Beta Was this translation helpful? Give feedback.
I came up with a solution, maybe it's not the best way, but it seems to work fine so far. What I do is, when rendering the table rows, make a check whether the current row has only one subRow. If it does, don't render; if it doesn't, render as normal. Like so: