Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: assign parentId to subRows when creating aggregatedRows #4882

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/table-core/src/utils/getGroupedRowModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ export function getGroupedRowModel<TData extends RowData>(): (
})

subRows.forEach(subRow => {
if (!subRow.parentId) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank for update

Object.assign(subRow, { parentId: id });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this also introduces a bug where the table will crash after ungrouping by a column. Needs to be looked into more, but this will be part of the solution.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch Kevin. I was so focused on the solution for my current use-case that I forgot about ungrouping 😢

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking into it, we have to find a way to remove the parentId as we ungroup.

Copy link
Author

@csantos1113 csantos1113 May 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to navigate this code, trying to follow the same approach for how the .depth value is assigned/unassigned.. But I see that property being modified in here:

So, I have couple questions:

  1. What is the difference between
    row.depth = depth
    groupedFlatRows.push(row)
    groupedRowsById[row.id] = row
    and the section I touched on this PR? mostly, they seem the same, but not sure why they happen in two diff places
  2. Would that better a place to assign/unassign the parentId 🤔?

Copy link
Author

@csantos1113 csantos1113 May 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😞 well, depth is also wrong

ungrouping the column keeps the rows depth: 1; 🛑

image

but they should go back to depth: 0 which is the expected value when ungrouped 🤕

image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what is worth:

assigning/un-assigning depth in v7 works just fine, here an example: https://codesandbox.io/s/amazing-water-pcepcv?file=/src/App.js

}

groupedFlatRows.push(subRow)
groupedRowsById[subRow.id] = subRow
// if (subRow.getIsGrouped?.()) {
Expand Down