Search code examples
javascriptpowerbi-custom-visuals

Is there possibilities of adding a drop down in format pane of a powerbi visual?


we are developing a powerbi custom visual where we are trying to change the visual's content based on a drop down selection. We came across powerbi capabilities and noticed that we could add ValueTypeDescriptor | StructuralTypeDescriptor ( which are basically input boxes or color fill ). Is there any possibility of adding a drop down from where the user can choose from pre-defined inputs.

Please refer the image to understand where we are trying to add the drop down list. enter image description here

I tried using couple of Visuals where I found drop down. But I couldn't figure out how to implement it. Please refer the below images.

Visual name - Multi row card. It had a drop down for font size

enter image description here

Visual Name - Map Which had a map type selection drop down

enter image description here


Solution

  • The data type you want for generic lists is an enumeration. Amazingly, I didn't realize the doc doesn't seem to have this list, which is quite unhelpful and probably why you're stuck... however, the API typings do list them. Here's a link to the current master branch where they're listed, but you can check your local powerbi-visuals-api module typings.

    Let's say you want a simple list, with two values. The syntax would be as follows:

    "type": {
        "enumeration": [
            {
                "displayName": "One",
                "value": "one"
            },
            {
                "displayName": "Two",
                "value": "two"
            }
        ] }
    

    So, the value displayed to the user is the displayName property and the value you would access in your code is the value property. You can also add displayNameKey properties if you're using the localization manager.

    For a font list, there's a pre-defined type called font family, which will generate a list of the supported fonts for youenter code here, e.g.:

    "type": {
        "formatting": {
            "fontFamily": true
        }
    }
    

    Note that you can't currently dynamically create entries in lists; they have to be defined in the capabilities to appear. You also can't add measures to dropdowns yet like the core visuals can :disappointed_face:

    Good luck!