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.
Hi developers,
I am trying to work out if (and how) I can persist a previously unknown number of properties in my custom visual. I have successfully persisted a single, static property so far. Now, I would like to persist an item of data per value, not knowing the number of values in advance. Can that be done? I'm adding some example code here that has no practical purpose, so please bear with me.
In order to achieve this, I want to add an object to the capabilities.json like this:
"misc": {
"displayName": "Miscellaneous",
"displayNameKey": "Visual_Persistent_Data",
"properties": {
"myPeristedStaticData": {
"type": {
"text": true
}
},
"myPersistedDynamicData": {
"type": {
"text": true
}
}
}
}
Naturally I will not be displaying these in the property pane. Instead, I will be replacing the "myPersistedDynamicData" with the properties I want to persist.
To my settings.ts I add the following:
export class VisualSettings extends DataViewObjectsParser {
public dataPoint: dataPointSettings = new dataPointSettings();
public misc: miscSettings = new miscSettings();
}
export class dataPointSettings {
public defaultColor: string = "";
public showAllDataPoints: boolean = true;
public fill: string = "";
public fillRule: string = "";
public fontSize: number = 12;
}
export class miscSettings {
public myPersistedStaticData: string = "";
public myPersistedDynamicData: string[] = [];
}
My aim is to populate the myPersistedDynamicData array with one item per value during the call to enumerateObjectInstances() by adding instances to the instanceEnumeration and then calling persisProperties(). I thought of something like this, but the dynamic part is not persisted:
private persist(noOfValues:number) {
for (i=0; i<noOfValues; i++) {
let propertyName = "property"+i.toString();
let objects: powerbi.VisualObjectInstancesToPersist = {
merge: [
<VisualObjectInstance>{
objectName: "misc",
selector: undefined,
properties: {
"myStaticPersistedData" : this.myStaticData,
propertyName : this.myDynamicData[i]
}
}]
};
}
this.host.persistProperties(objects);
}
How can I dynamically add properties and persist them?
Thanks for reading this far!
Hi @WouterBo ,
Objects and properties of Power BI visuals - Power BI | Microsoft Docs
Hope the official documentation can help you.
Best regards,
Lionel Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
It cannot Lionel, but hope springs eternal I suppose.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
15 | |
2 | |
1 | |
1 | |
1 |
User | Count |
---|---|
24 | |
3 | |
2 | |
2 | |
2 |