Forum Discussion
Power BI Custom Visual state persistence
- 5 years ago
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
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