Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi all,
I am building a custom table, so basically my table has some expandable/collapsible rows.
I am using React, so whenever I filter for new data, the expanded rows remain. That's great, expected behavior.
However, when I go to another page and come back, the visual re-initializes, which means I lose all the current states.
With default table/matrix, I don't encounter such problems.
Is there anyway I can persist those states
I know there is a thing called persistProperties, but AFAIK it persists "Format Pane" only.
Thank you all.
Solved! Go to Solution.
Hi @marrocksd
persistProperties is indeed the right way to do this, as React state is lost when the visual is destroyed. The only way to store anything you want persisted in a visual for when it's next instantiated is to use the objects/properties, as the developer visual sandbox prevents cookies and local storage. You would restore the property into your visual state from here when the visual's update method runs and settings are enumerated.
A property doesn't have to be visible in the pane, but does have to be declared in your capabilities.json and available to your VisualSettings. However, you can remove that property from the formatting pane during enumerateObjectInstances (or, if you are manually pushing in the objects, like the sample bar chart, you can just omit it) so that the user doesn't see it. It will still be present in your visual's objects as a persistable property.
If your property is a complex object that doesn't fit the data types that capabilities.json offers, you can declare a text property in your capabilities and stringify the JSON for storage (and then parse it when settings are enumerated).
Regards,
Daniel
Proud to be a Super User!
On how to ask a technical question, if you really want an answer (courtesy of SQLBI)
Hi @dm-p , one other thing. It's about when to persist the state.
Currently I'm persisting all states everytime the user expands or collapses a row... sound not good for performance at all.
I've tried:
- public destroy() method in Visual class
- public componentWillUnmount method in Visual class
- React useEffect(... return...) in my component
None works, could you help me please, thanks a ton
Thanks alot @dm-p . I'll try that right now but I believe that's the right way.
I have been using useState hook. So it would be easy to add a listener to save and persist all states, then load them as init states next time.
Hi @marrocksd
persistProperties is indeed the right way to do this, as React state is lost when the visual is destroyed. The only way to store anything you want persisted in a visual for when it's next instantiated is to use the objects/properties, as the developer visual sandbox prevents cookies and local storage. You would restore the property into your visual state from here when the visual's update method runs and settings are enumerated.
A property doesn't have to be visible in the pane, but does have to be declared in your capabilities.json and available to your VisualSettings. However, you can remove that property from the formatting pane during enumerateObjectInstances (or, if you are manually pushing in the objects, like the sample bar chart, you can just omit it) so that the user doesn't see it. It will still be present in your visual's objects as a persistable property.
If your property is a complex object that doesn't fit the data types that capabilities.json offers, you can declare a text property in your capabilities and stringify the JSON for storage (and then parse it when settings are enumerated).
Regards,
Daniel
Proud to be a Super User!
On how to ask a technical question, if you really want an answer (courtesy of SQLBI)
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
7 | |
7 | |
3 | |
2 | |
2 |
User | Count |
---|---|
6 | |
5 | |
4 | |
4 | |
4 |