table icon indicating copy to clipboard operation
table copied to clipboard

cell.getIsAggregated should not check for zero length subrows

Open tmax22 opened this issue 8 months ago • 2 comments

TanStack Table version

table-core v8.17.3

Framework/Library version

react

Describe the bug and the steps to reproduce it

current implementation for cell.getIsAggregated is

https://github.com/TanStack/table/blob/22e1ac4e8536fb959093574b0e2d42d3faa6f992/packages/table-core/src/features/ColumnGrouping.ts#L396

i would argue that row.subRows?.length is not supposed to be there.

look:

image

as we can see, aggregated cells exists even if no subrows exists for this group. this happens on custom getGroupedRowModel that i implement that makes sure that certain grouping values always exists even if there is no current rows for them(full explanation).

this is not a bug, but rather would say unexpected behavior for the method cell.getIsAggregated. i would argue that at least the next major release should change this behavior.

in my case, checking for row.depth === 0 instead is enough:

const customIsAggregated = !cell.getIsGrouped() && !cell.getIsPlaceholder() && row.depth === 0;
  let renderedCellValue =
    customIsAggregated && columnDef.AggregatedCell
...

image

Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

.

Screenshots or Videos (Optional)

No response

Do you intend to try to help solve this bug with your own PR?

Yes, I think I know how to fix it and will discuss it in the comments of this issue

Terms & Code of Conduct

  • [X] I agree to follow this project's Code of Conduct
  • [X] I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.

tmax22 avatar Jun 15 '24 20:06 tmax22