Arthur Deryckere
Arthur Deryckere

Reputation: 1

Power-Bi JavaScript: Data Selected-, Button Clicked- Event not triggered

MS Playground: https://microsoft.github.io/PowerBI-JavaScript/demo/v2-demo/index.html#

Context

  1. The report is loaded correctly
  2. "Loaded" and "Rendered" events are triggered correctly
  3. "powerbi-client": "^2.7.0",

MS Example to listen for "dataSelected"

// Get a reference to the embedded report HTML element
var embedContainer = $('#embedContainer')[0];

// Get a reference to the embedded report.
report = powerbi.get(embedContainer);

// Report.off removes a given event listener if it exists.
report.off("dataSelected");

// Report.on will add an event listener.
report.on("dataSelected", function(event) {
    Log.logText("Event - dataSelected:");
    var data = event.detail;
    Log.log(data);
});

// Select Run and select an element of a visualization.
// For example, a bar in a bar chart. You should see an entry in the Log window.

Log.logText("Select data to see events in Log window.");

My TypeScript Implementation

const report: Embed = pbiService.embed(container, reportConfig);

report.on("dataSelected", event => {
  console.log("dataSelected", event);
});
report.on("buttonClicked", event => {
  console.log("buttonClicked", event);
});

Prints the correct amount and named EventHandlers:

console.log(report.eventHandlers);

Issue

"dataSelected" and "buttonClicked" are never triggered.

Upvotes: 0

Views: 3998

Answers (2)

Mikhail Kh
Mikhail Kh

Reputation: 206

In pbix report, in Button setup turn on action switch - this will add action to button.

I add open bookmark action without reference to any bookmark.

And now click on that button still do nothing in report, but it rise button click event which you may caught in you application.

Upvotes: 2

Breno Oliveira
Breno Oliveira

Reputation: 53

You're creating a report object of type Embed. You can try doing this with Report type, like this:

import { Report } from 'report'; // This is part of powerbi-client library

const report: Report = <Report> pbiService.embed(container, reportConfig));

report.on("dataSelected", event => {
  console.log("dataSelected", event);
});
report.on("buttonClicked", event => {
  console.log("buttonClicked", event);
});

Upvotes: 1

Related Questions