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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
filipwydra
Frequent Visitor

Overwrite default value from property panel

Hello everyone,

 

I have a custom visual where user can drag the horizontal line which change the column width. Default value is set to 125.

I try to figure out how to ovewrite the default value from property panel like this:

filipwydra_0-1673349406483.png

 

I did try to overwite the value this way:

this.settings.columnProps.column_one = currentLines[0].getBoundingClientRect().left;

 

... but it doesn't work. When refresh the report the value back to default. 

 

Is there any API or ready solution to do this ? Can I use come kind of local storage ? 

Thanks for any help!

1 ACCEPTED SOLUTION
dm-p
Super User
Super User

Hi @filipwydra,

When properties are loaded into your visual from the pane, they are not bi-directional, so if you're updating a value in your visual, it will not be written back to the main window (which is where your visual properties are persisted so they can be restored when your visual re-initialises). If you wish to programmatically update them from within your visual, you will need to use the persistProperties method from the visual host.

This object is only grabbable when your visual is initialised, so when your constructor runs, store the options.host object in a variable that can be accessed within your visual and then use this method to update the visual properties accordingly. When building your VisualObjectInstancesToPersist object, I'd suggest using merge as the desired instance, as this will create or replace the property (rather than replace, which assumes the property value already exists).

The visual host service is useful for other things that require communication with the main window, such as creating selectors (for cross-filtering and tooltips), and the API for IVisualHost is visible here in the powerbi-visuals-api repo (although you can view it in VS Code by inspecting VisualConstructorOptions definition and following through also).

Regards,

Daniel





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

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


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




View solution in original post

2 REPLIES 2
filipwydra
Frequent Visitor

Daniel (@dm-p ), this is exactly what I need. Thank you!

dm-p
Super User
Super User

Hi @filipwydra,

When properties are loaded into your visual from the pane, they are not bi-directional, so if you're updating a value in your visual, it will not be written back to the main window (which is where your visual properties are persisted so they can be restored when your visual re-initialises). If you wish to programmatically update them from within your visual, you will need to use the persistProperties method from the visual host.

This object is only grabbable when your visual is initialised, so when your constructor runs, store the options.host object in a variable that can be accessed within your visual and then use this method to update the visual properties accordingly. When building your VisualObjectInstancesToPersist object, I'd suggest using merge as the desired instance, as this will create or replace the property (rather than replace, which assumes the property value already exists).

The visual host service is useful for other things that require communication with the main window, such as creating selectors (for cross-filtering and tooltips), and the API for IVisualHost is visible here in the powerbi-visuals-api repo (although you can view it in VS Code by inspecting VisualConstructorOptions definition and following through also).

Regards,

Daniel





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

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


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




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors