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

getIsAllRowsExpanded #4216

Closed
2 tasks done
sjbuysse opened this issue Jul 24, 2022 · 5 comments
Closed
2 tasks done

getIsAllRowsExpanded #4216

sjbuysse opened this issue Jul 24, 2022 · 5 comments

Comments

@sjbuysse
Copy link

sjbuysse commented Jul 24, 2022

Describe the bug

This does not work, and it looks incorrect in the source code

        // If any row is not expanded, return false
        if (table.getRowModel().flatRows.some(row => row.getIsExpanded())) {
          return false
        }

I'm guessing there should be a ! in front of that row.getIsExpanded() ?
I've never contributed to an OS project, and unfortunately a bit short on time to figure it out at the moment

Your minimal, reproducible example

x

Steps to reproduce

x

Expected behavior

x

How often does this bug happen?

No response

Screenshots or Videos

x

Platform

x

react-table version

latest

TypeScript version

No response

Additional context

No response

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • 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.
@simplecommerce
Copy link

I am adding a comment here because I think this issue is still not fixed.

If look at the code here: https://github.com/TanStack/table/blob/main/packages/table-core/src/features/Expanding.ts#L131

I am having the issue on my project, and it seems to be related to this.

Was it supposed to be already fixed? I am using latest version 8.5.11

@pixelbucket-dev
Copy link

pixelbucket-dev commented Aug 28, 2023

In my opinion this is still broken. For the line @simplecommerce marked, what should be done here is, that you only want to check whether ONLY the rows that contain subRows are expanded or not. Non-expandable rows will ALWAYS return false.

I believe, this is the correct code for the marked line above (@simplecommerce). WDYT?

const areSomeExpandableRowsCollapsed = table
    .getRowModel()
    .flatRows.filter((row) => !!row.subRows?.length)
    .some((row) =>!row.getIsExpanded())

if (areSomeExpandableRowsCollapsed) {
    return false
}

or

const areSomeExpandableRowsCollapsed = table.getRowModel().flatRows.some((row) => {
    const isRowExpandable = row.subRows?.length

    return isRowExpandable && !row.getIsExpanded()
  })

if (areSomeExpandableRowsCollapsed) {
    return false
}

Note: I've extracted some conditions to variables for easier readability.

@simplecommerce
Copy link

getIsExpanded

I forgot about this one, I think I did something similar on my end to bypass it and I used getRowCanExpand to check if my row has sub rows like you mentioned.

@pixelbucket-dev
Copy link

pixelbucket-dev commented Aug 28, 2023

Thanks for confirming this.

I've improved the readability of the above:

return table.getRowModel().flatRows.some((row) => {
    const isRowExpandable = !!row.subRows?.length

    if (!isRowExpandable) {
      return false
    }

    const isRowCollapsed = !row.getIsExpanded()

    return isRowCollapsed
})

I also have a problem with toggleAllRowsExpanded() once all expandable rows are expanded. On the initial click, the rows stay expanded. I have to click a second time to make them collapsed. I hacked around this with this code:

function onToggleAllRowsExpanded() {
  const isAllExpandableRowsExpanded = !areSomeExpandableRowsCollapsed

  if (isAllExpandableRowsExpanded) {
    table.resetExpanded()
    return
  }

  table.toggleAllRowsExpanded()
}

This is probably an unrelated bug, but worth mentioning. If it's confirmed I can create an issue for it.

@simplecommerce
Copy link

Thanks for confirming this.

I've improved the readability of the above:

return table.getRowModel().flatRows.some((row) => {
    const isRowExpandable = !!row.subRows?.length

    if (!isRowExpandable) {
      return false
    }

    const isRowCollapsed = !row.getIsExpanded()

    return isRowCollapsed
})

I also have a problem with toggleAllRowsExpanded() once all expandable rows are expanded. On the initial click, the rows stay expanded. I have to click a second time to make them collapsed. I hacked around this with this code:

function onToggleAllRowsExpanded() {
  const isAllExpandableRowsExpanded = !areSomeExpandableRowsCollapsed

  if (isAllExpandableRowsExpanded) {
    table.resetExpanded()
    return
  }

  table.toggleAllRowsExpanded()
}

This is probably an unrelated bug, but worth mentioning. If it's confirmed I can create an issue for it.

haven't had the issue, I use getToggleAllRowsExpandedHandler and it seems ok on my end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants