table icon indicating copy to clipboard operation
table copied to clipboard

Extending react-table using composition stops methods from working

Open roberthchapman opened this issue 8 years ago • 1 comments

Hi, I've worked out how to extend react-table using composition, however I don't yet understand how to manage methods at multiple levels. I have a component that uses getTrProps to apply styling for all react-tables that we use. That gets applied for the extended component. But at the individual level it also needs getTrProps to add click handlers, and at the moment neither of them are run.

Extended-react-table itself has:

getTrProps={this.normalRows} and then: 

normalRows = (state, rowInfo, column) => {
    return {    style: { height:40, display:'flex', alignItems: 'center'}   }
}

while the usage of extended-react-table has:

    getTrProps={this.rows}  and then:

    rows = (state, rowInfo) => {
        return {   onClick: e => { this.props.openProduct(rowInfo.original); }  }
    }

Clearly they interfere with each other. What means should I be using to ensure that the events run at both levels? Or do I need to combine the props rather than have it run at both levels? So this.normalRows combined somehow with this.props.getTrProps? Thanks

roberthchapman avatar Oct 19 '18 11:10 roberthchapman

You would need to compose the functions effects together, though this is an edge case that currently isn't officially supported.

This feature/issue has been tagged as one that will likely be fixed or improved in the next major release of React-Table. This release is expected to be completed in the next 6 - 8 months. Please see #1143 for more detail. If you believe this feature can be easily fixed, we invite you to fork the project, attempt the fix, and use it until the latest version is available. If the fix is simple enough, we will also consider it as a PR to the current version.

tannerlinsley avatar Oct 24 '18 17:10 tannerlinsley