Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

213
Views
How to toggle row selection mode in react-table v7 with useRowSelect

I'm facing a problem with react-table v7.8.0 and useRowSelect plugin. All I want is to toggle the selection mode by setting a state variable, so that I'm able to show or hide the additional selection column just by clicking a button like "toggle selection mode for table".

That's what I'm trying in my code:

const {
    getTableProps,
    getTableBodyProps,
    headerGroups,
    prepareRow,
    rows,
    state,
    page,
    canPreviousPage,
    canNextPage,
    pageOptions,
    pageCount,
    gotoPage,
    nextPage,
    previousPage,
    setPageSize,
    allColumns,
    state: { pageIndex, pageSize, selectedRowIds },
    preGlobalFilteredRows,
    setGlobalFilter
  } = useTable({    columns, 
                    data, 
                    
                }, 
                    useGlobalFilter, 
                    useSortBy, 
                    usePagination,
                    useRowSelect,
                    hooks => {
                        
                        
                            hooks.visibleColumns.push(columns => { 
                                
                                return [
                                (tableRowsSelectable === true ? {
                                    id: 'selection',
                                    Header: ({getToggleAllRowsSelectedProps}) => (
                                        <div><Checkbox {...getToggleAllRowsSelectedProps()} /></div>
                                    ),
                                    Cell: ({row}) => (<div><Checkbox {...row.getToggleRowSelectedProps()} /></div>)
                                }: []),
                                ...columns,
                            ]})
                            
                    })

The tableRowsSelectable, that is set as property (either true or false) for the react-table component, is my attempt to control the selection mode. But that does not work. Nothing happens, when I change tableRowsSelectable.

By the way: Do not consider Checkbox component. It is just a custom component and works as expected.

What else can I do?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!