From a0f1cc3f26ae4e2debf215bebd9fe9046c34cfee Mon Sep 17 00:00:00 2001 From: Kevin Vandy Date: Sun, 30 Jun 2024 08:56:38 -0500 Subject: [PATCH] getIsSomeRowsSelected should not return false when all rows are selected --- examples/react/row-selection/src/main.tsx | 2 +- .../table-core/src/features/RowSelection.ts | 17 ++++------------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/examples/react/row-selection/src/main.tsx b/examples/react/row-selection/src/main.tsx index 05a22ca29e..9188fbbdc8 100644 --- a/examples/react/row-selection/src/main.tsx +++ b/examples/react/row-selection/src/main.tsx @@ -1,4 +1,4 @@ -import React, { HTMLAttributes, HTMLProps } from 'react' +import React, { HTMLProps } from 'react' import ReactDOM from 'react-dom/client' import './index.css' diff --git a/packages/table-core/src/features/RowSelection.ts b/packages/table-core/src/features/RowSelection.ts index a80c2d91c6..1939394791 100644 --- a/packages/table-core/src/features/RowSelection.ts +++ b/packages/table-core/src/features/RowSelection.ts @@ -431,22 +431,13 @@ export const RowSelection: TableFeature = { } table.getIsSomeRowsSelected = () => { - const totalSelected = Object.keys( - table.getState().rowSelection ?? {} - ).length - return ( - totalSelected > 0 && - totalSelected <= table.getFilteredRowModel().flatRows.length - ) + return Object.keys(table.getState().rowSelection ?? {}).length > 0 } table.getIsSomePageRowsSelected = () => { - const paginationFlatRows = table.getPaginationRowModel().flatRows - return table.getIsAllPageRowsSelected() - ? false - : paginationFlatRows - .filter(row => row.getCanSelect()) - .some(d => d.getIsSelected() || d.getIsSomeSelected()) + return table + .getPaginationRowModel() + .flatRows.some(r => r.getIsSelected() || r.getIsSomeSelected()) } table.getToggleAllRowsSelectedHandler = () => {