microsoft / PowerBI-visuals-ChicletSlicer

Repo for Power BI Chiclet Slicer custom visual
Other
65 stars 60 forks source link

Slicer API not working #66

Open tzake opened 5 years ago

tzake commented 5 years ago

setSlicerState is not working (in Power BI Embedded)

is it because this is not a real "slicer" type? (naming reveals the visual.type is ChicletSlicer1448559807354)

also, would it support setting the state by the Values and not the Category field? this would be very useful

rcampbell22 commented 5 years ago

We encountered a similar issue with this control and the Slicer API. We were able to get setSlicerState to work by finding the visual once the report was loaded (i.e. on a button click) and using the sample from https://github.com/Microsoft/PowerBI-JavaScript/wiki/Slicers#native-slicers:

const basicFilter = {
  $schema: "http://powerbi.com/product/schema#basic",
  target: {
    table: "Store",
    column: "Count"
  },
  operator: "In",
  values: [1,2,3,4],
  filterType: pbi.models.FilterType.BasicFilter
};

visual.setSlicerState({
    filters: [basicFilter]
});

but when trying to set the same filter on the same slicer on load (as per https://github.com/Microsoft/PowerBI-JavaScript/wiki/Slicers#setting-slicers-on-report-load), we got an error that the visual was not of type 'slicer' when using the "ISlicerTargetSelector" method, and we got console errors during the embed when using the "IVisualSelector" method.

When we changed the control to a regular slicer, all 3 methods (button click, TargetSelector on load and VisualSelector on load) all worked as expected.

sigma-scott commented 3 years ago

I am attempting to execute setSlicerState with a chiclet slicer and I am not getting it to work even if the report is loaded. As a test to see how this worked in general, I opened an immediate window in Chrome, changed the slicer state, called getSlicerState on the visual, manually set the chiclet slicer to something different, then attempted to use setSlicerState to restore the state. There was no error reported, but setSlicerState had no effect. A subsequent call to getSlicerState returned the state I had manually changed the state.

// 1. Manually set the Chiclet Slicer to a state that I want.
// 2. Get the slicer state - This works, value of state output below.
let state = await visual.getSlicerState();

// 3. Manually change the Chiclet Slicer to a different state.
// 4. Attempt to restore the slicer state.
await visual.setSlicerState(state);

// No error, but no visual affect and repeating the call in 2 returns 3's state, not 2's.

This is the JSON from the call in 2.

[{
        "filters": [{
                "$schema": "http:\/\/powerbi.com\/product\/schema#basic",
                "target": {
                    "table": "Retention Level",
                    "column": "Value"
                },
                "filterType": 1,
                "operator": "In",
                "values": [500000],
                "requireSingleSelection": false
            }
        ]
    }
]
jfrseeley commented 2 years ago

I'm able to get setSlicerState to work for chiclet slicers, so long as the report has been clearly loaded. For example:

visual.setSlicerState({
  filters: [
    {
      $schema: 'http://powerbi.com/product/schema#basic',
      filterType: pbi.models.FilterType.Basic,
      operator: 'In',
      target: {
        table: 'SomeTable',
        column: 'SomeColumn'
      },
      values: ['SomeValue']
    }
  ]
});

I just can't get the embed function to do anything meaningful for chiclet slicers. Where normal slicers work, those specified for chiclet slicers result in this error: "{message: 'slicerTargetDoesNotMatch', detailedMessage: 'Filters target doesn't match slicer target', level: 3}"

this.report = this.pbiService.embed(element, {
  // ...

  slicers: [
    {
      selector: {
        $schema: 'http://powerbi.com/product/schema#slicerTargetSelector',
        target: {
          table: 'SomeTable',
          column: 'SomeColumn'
        }
      },
      state: {
        filters: [
          {
            $schema: 'http://powerbi.com/product/schema#basic',
            filterType: pbi.models.FilterType.Basic,
            operator: 'In',
            target: {
              table: 'SomeTable',
              column: 'SomeColumn'
            },
            values: ['SomeValue']
          }
        ]
      }
    }
  ]

  // ...
});

Conversely, if I change the selector to something resembling the below, I instead get this error any time my visual name is targeting a chiclet slicer: "TypeError: Cannot read properties of undefined (reading 'objects')"

selector: {
   $schema: 'http://powerbi.com/product/schema#visualSelector',
   visualName: 'c02019206bd1728b6ca2'
}

Finally, chiclet slicers don't come back in the API when calling getSlicers from the page object; just normal slicers. I'm not sure if that's a helpful lead or not, but it seems like chiclet slicers are missing out on certain native benefits for not being first-class citizens.