React-table: Unable to deselect row

Created on 20 Dec 2019  Â·  11Comments  Â·  Source: tannerlinsley/react-table

Unable to deselect row when applied with Filter Column

Steps to Reproduce:

  1. Filter by any column (Works as Expected)
  2. Select particular row by ticking checkbox. (Works as Expected)
  3. Deselect same row (Doesn't Works as Expected)

bug

Laptop Info

  • MacBook Pro (Retina, 13-inch, Early 2015) (Mojave- 10.14.4)
  • Browser: Chrome Version 79.0.3945.79 (Official Build) (64-bit)

Most helpful comment

This will be fixed in the next release.

All 11 comments

Looking in to this asap

This will be fixed in the next release.

Hey, I just ran across this myself. Was wondering if a fix was ready on master awaiting a release, or if you still needed someone to fix it.

In node-modules/react-table/dist/index.js, on line number 2869
replace this line
var isSelected = row.isSelected;
with
var isSelected = state.selectedRowIds[row.id];
Hence, getting value of isSelected from the state instead of the row instance
Refer the attached image
row-deselect-fix

I ended up adding a plugin with a useInstance lifecycle that goes between useFilters and useRowSelect. The root cause of this seems to be useFilters generating rows and flatRows arrays that have different objects in them. My plugin just re-generates flatRows from rows before things get passed to useRowSelect.

When is the fix planned to be released? I can still replicate here with the latest version.

Any solution please? As this is really holding us back from using this library and we absolutely can't wait to use it because it's amazing @tannerlinsley Thank you so much.

@ifen Try this: https://gist.github.com/fionawhim/c49fa6cb2257af0a03fb7e09ea1e7583

And use it like this:

  return useTable(
    {
      columns,
      data: groupedFeatures,
      …
    },
    useFilters,
    useFiltersPatch,
    useRowSelect
  );

It works by re-creating flatRows so that it’s made of the same objects that are in rows. Note: I haven’t tested this on grouped rows or anything.

This is fixed in master and slated for release. Thanks for your help everyone!

@tannerlinsley I just cloned/built the repo and used yarn link to try out the master branch in my app. I’m still seeing this bug occur: if a filter is active on the table, deselection doesn’t work.

I looked over the code in the repo and I hypothesize that rows and flatRows containing different object instances when there’s a filter is causing the problem.

Good to know. I’ll dig deeper.
On Feb 14, 2020, 2:58 PM -0700, Fiona Hopkins notifications@github.com, wrote:

@tannerlinsley I just cloned/built the repo and used yarn link to try out the master branch in my app. I’m still seeing this bug occur: if a filter is active on the table, deselection doesn’t work.
I looked over the code in the repo and I hypothesize that rows and flatRows containing different object instances when there’s a filter is causing the problem.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

panfiva picture panfiva  Â·  3Comments

ocalde picture ocalde  Â·  3Comments

dilipsundarraj1 picture dilipsundarraj1  Â·  3Comments

pasichnyk picture pasichnyk  Â·  3Comments

monarajhans picture monarajhans  Â·  3Comments