Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand component rendered at table construction? #1299

Closed
RichardYang2016 opened this issue May 9, 2017 · 12 comments
Closed

Expand component rendered at table construction? #1299

RichardYang2016 opened this issue May 9, 2017 · 12 comments

Comments

@RichardYang2016
Copy link

Hi there,

So the scenario is, in my redux store I have a node for data of current expanded row, and all rows are expandable.

In debug I find that, such component are constructed for each and every row of the table, even if the row is not expanded. Plus, my redux node of current opened row are rendered to all components for the rows. Only difference is the components are hidden except the current selected row.

Is there a way to not render all those expand components at the construction of the table itself, but rather render it and destruct it every time I expand/collapse a row?

Thanks, Richard.

@AllenFang
Copy link
Owner

AllenFang commented May 10, 2017

did you means you want to render the expanding content when the row is expanded? and destroy is when it collapse?

@RichardYang2016
Copy link
Author

@AllenFang Hi Allen
Actually I did achieve my goal by moving the API call to onSelect event, and compare id of the row to the fetched id to only render subcomponent for the current expanded row.

but this brings another small issue, when click the row again to collapse, the API is triggered again. I don't see any information in the documentation that I can get indicators from any event to tell if a row is expanded or collapsed. for example, properties like row.expanded. This could be a good enhancement if currently not supported.

Thanks, Richard.

@AllenFang
Copy link
Owner

I think use onSelect is also a workaround, but not the best solution and maybe I can support a hook function for you, called onExpand or something. i think it's much intuitive for developer

@RichardYang2016
Copy link
Author

That would be great Allen! Thanks a lot !

Regards, Richard.

@AllenFang
Copy link
Owner

hello @RichardYang2016, check this, I support the options .onExpand on v3.3.5.

@RichardYang2016
Copy link
Author

Thank you so much Allen!

@zillerium
Copy link

I am getting a similar issue with the expand causing the expandComponent to be accessed for every row regardless of whether the user clicked expand or now. How is the onExpand implemented? Here is my code - https://github.com/zillerium/zmes/tree/master/zmes/src

@AllenFang
Copy link
Owner

Hey fork, I've no time to check your repo, it too big to me, give me the point or check this example, thanks

@zillerium
Copy link

Fork the entire repo for asking a question?

@RichardYang2016
Copy link
Author

obviously he actually meant 'folk'... don't be panic.

anyway I do recommend you looking at the example provided. put a event handler for onExpand in place and put a debug point to look at the event itself you should be able to figure out how to use it. It does solve my problem earlier. pretty neat.

@eyalap
Copy link

eyalap commented Jan 2, 2018

@zillerium @RichardYang2016
I experienced the same thing and ended up doing something similar to what Allen suggested.
I had a heavy component rendered in my expanded component and with a table of 50 rows it already got slow.
This way I can have multiple expanded rows with data, and even tough I still have a component rendered to the DOM it's an empty component which is cheap.
I still think it should be the default behavior and managed internally in the component and not like this.

this.state = {
expanding: {},
}

handleExpand(rowKey, isExpand, e) {
if (isExpand) {
const newExpandingKeys = this.state.expanding;
newExpandingKeys[rowKey] = true;
this.setState({
expanding: newExpandingKeys,
})
} else {
const newExpandingKeys = this.state.expanding;
delete newExpandingKeys[rowKey];
this.setState({
expanding: newExpandingKeys,
})

}

}

expandComponent(row) {
return this.state.expanding[row._key] ? this.props.expandComponent(row) : null
}

const options = {
onExpand: this.handleExpand,
};

<BootstrapTable ...... expandComponent={this.expandComponent} >

@kevin-daniel-hunt
Copy link

Rendering every expanded column at table construction and not rendering the expansion when the row is expanded is incredibly unintuitive and will cause serious load-time issues for me as well. Is there still no workaround, implementation, or fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants