Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join 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.

Reply
marrocksd
Regular Visitor

Power BI Custom Visual state persistence

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.

Capture.PNG

 

1 ACCEPTED SOLUTION
dm-p
Super User
Super User

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





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




View solution in original post

3 REPLIES 3
marrocksd
Regular Visitor

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

marrocksd
Regular Visitor

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.

dm-p
Super User
Super User

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





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.