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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
popeadam
New Member

Context menu for visualisation that doesn't need it....

I have a visualisation which has no great need for a context menu other than to be consistent with other Power BI custom visuals. The visual does not use the d3 library, and I can't find a sample to copy off which also doesn't. I'm wondering how I might be able to incorporate it easily?

The current code I'm using is as follows, and it gets all a bit messy in the 'private handleContextMenu' method:

 

import ISelectionManager = powerbi.extensibility.ISelectionManager;

export class Visual implements IVisual {
  private selectionManager: ISelectionManager;
}
constructor(options: VisualConstructorOptions) {
        this.handleContextMenu();
}
private handleContextMenu() {
        const mouseEvent: MouseEvent = addEventListener as MouseEvent;
        const eventTarget: EventTarget = mouseEvent.target;
        this.selectionManager.showContextMenu(Selection, { x: MouseEvent.clientX, y: MouseEvent.clientY });
          mouseEvent.preventDefault();
  }
Is anyone able to provide a method which would be able to enable the default context menu of 'Show as table/copy/chat in teams'?
1 REPLY 1
popeadam
New Member

Managed to resolve this using the d3 library:

 

import {select} from "d3";

export class Visual implements IVisual {
  private selectionManager: ISelectionManager;

  constructor(options: VisualConstructorOptions) {
        this.selectionManager = options.host.createSelectionManager();
        this.handleContextMenu();
    }
    private handleContextMenu() {
        select(this.target).on("contextmenu", (event: MouseEvent) => {
            this.selectionManager.showContextMenu({}, {
                x: event.clientX,
                y: event.clientY,
            });
            event.preventDefault();
        });
    }


 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors