1

I am using react-table for the data-grid purpose. I am implementing a settings icon which shows the list of columns and based on the selection, the column gets shown or hidden. I am manipulating "show" property of columns object for this. While the property is getting set properly, there is no such change in the table. Can someone help me with this.

But when I set the property directly(in App component) it works. Where am I going wrong?

Code Sandbox: https://codesandbox.io/s/blue-cherry-di3ub

Help would be appreciated

1 Answer 1

1

The issue is in your Select

this.props.handleSetState(this.props.data)

this.props.data is immutable, so you're just sending back the same data that came in. Stream props.data into a new object and then send that back to the parent.

ETA: Something like this...

    let updatedObj = this.props.data.map((obj, i) => {
      if (obj.accessor === value[i]) {
        obj.show = false
      }
      return obj
    })
    this.props.handleSetState(updatedObj);
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the answer. Is it possible for you to share the logic? I am a bit new to react
I think I was just using it incorrectly. I thought the checkboxes were to indicate which were hidden and which were not. It's just there to flip them, in which case your logic is fine
But if this answered your question, could you accept/vote up? Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.