question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`defaultCanSort` not setting canSort to false in columns

See original GitHub issue

I set the defaultCanSort option as described in the docs:

 const {
    getTableProps,
    getTableBodyProps,
    headerGroups,
    rows,
    prepareRow
  } = useTable(
    {
      columns,
      data,
      defaultCanSort: false
    },
    useSortBy
  );

Unfortunately when logging columns, they all still return canSort: true, which means some of my unsortable headers are all styled as sortable.

Example As you can see below, the columns marked ‘sortable’ are receiving canSort as true, even though defaultCanSort is set to false and names is the only column with canSort set.

https://codesandbox.io/s/flamboyant-chebyshev-ksdy3

**Expected behavior ** Setting defaultCanSort to false in the options object should mean all columns are marked as canSort false by default.

  • OS: OSX
  • Browser: Firefox

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
tannerlinsleycommented, Apr 1, 2020

The docs need to be more clear here maybe, but that default only applied to columns without accessors. If a column has an accessor, you will need to set canSort on the column or even extend the default column options so all columns have canSort: false

0reactions
dpoveycommented, Dec 3, 2021

I have a similar issue, in my case I had to set canSort: true on the column but this is not covered by Typescript definitions so had to hack it in. Be good if the documentation and types could be updated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

defaultCanSort not setting canSort to false in columns #2080
Setting defaultCanSort to false in the options object should mean all columns are marked as canSort false by default. OS: OSX; Browser: Firefox....
Read more >
How to do default sorting in react-table - Stack Overflow
In order to sort a column (or columns) when the table is built, you just have to set the sortBy array on the...
Read more >
Sorting | TanStack Table Docs
Set to true for sorting toggles on this column to start in the descending direction. enableSorting. tsx. enableSorting?: boolean.
Read more >
Sorting Feature Guide - Material React Table Docs
Sorting can be disabled globally by setting the enableSorting prop to false . This will disable sorting for all columns. You can also...
Read more >
react-table@7.7.0 - Bundle Scanner
nThis usually means you need to need to name your plugin hook by setting the ... getFirstDefined(defaultCanSort, defaultColumnCanSort, false); column.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found