table icon indicating copy to clipboard operation
table copied to clipboard

getIsSomeRowsSelected() does not trigger when all rows are selected

Open Serpentarius13 opened this issue 1 year ago • 1 comments

TanStack Table version

^8.20.5

Framework/Library version

React 18

Describe the bug and the steps to reproduce it

I don't understand why do those handlers exclude each other in implementation. Isn't it the basic rule of logic that when everything is selected, part is deemed selected too? In implementation its not like this by some reason, specifically checking that there shouldn't be every row selected to return true:

table.getIsSomeRowsSelected = () => {
      const totalSelected = Object.keys(
        table.getState().rowSelection ?? {}
      ).length
      return (
        totalSelected > 0 &&
        totalSelected < table.getFilteredRowModel().flatRows.length
      )
}

I think it just causes additional computations if I want to create a global checkbox to select every row. What is the reasoning behind this?

Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

https://stackblitz.com/edit/tanstack-table-y5enqv?file=src%2Fmain.tsx

Screenshots or Videos (Optional)

Image

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.

Serpentarius13 avatar Sep 07 '24 18:09 Serpentarius13

I ran into the same issue today and I'm not sure this is a bug. We're using getIsSomeRowsSelected() to set indeterminate on a checkbox, and getIsAllRowsSelected() to set checked.

The documentation around it may need updating though.

karlshea avatar Aug 07 '25 22:08 karlshea