<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic jquery-contextmenu in custom visual in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/jquery-contextmenu-in-custom-visual/m-p/733116#M19892</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After loading&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;&lt;SPAN&gt;&lt;EM&gt;jquery-contextmenu&lt;/EM&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;using:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;npm i jquery-contextmenu
npm i @types/jquery.contextmenu&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;and adding the javascript using:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;this.contextmenuScript = d3.select(this.element).append('script');
this.contextmenuScript.attr({
	type: 'text/javascript',
	class: 'showcase'
});
this.contextmenuScript.text("$(function() { $.contextMenu({ selector: '.context-menu-one', callback: function(key, options) { var m      ...&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;I get the following&amp;nbsp;error: '&lt;/SPAN&gt;&lt;SPAN&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;&lt;EM&gt;VM3309:1 Uncaught TypeError: $.contextMenu is not a function&lt;/EM&gt;&lt;/FONT&gt;&lt;/STRONG&gt;'&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Do I need to import the javascript explicitly? If so, how?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What is the correct way to add the context menu code above?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am using PBIVIZ v3.1.2 / ES6.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/swisnl/jQuery-contextMenu" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;Github&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Working example in &lt;A href="https://jsfiddle.net/phpdeveloperrahul/eraLr0z8/" target="_blank" rel="noopener"&gt;JSFiddle&lt;/A&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks for any help.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Martijn&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 06 Jul 2019 02:41:22 GMT</pubDate>
    <dc:creator>Blaenzo</dc:creator>
    <dc:date>2019-07-06T02:41:22Z</dc:date>
    <item>
      <title>jquery-contextmenu in custom visual</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/jquery-contextmenu-in-custom-visual/m-p/733116#M19892</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After loading&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;&lt;SPAN&gt;&lt;EM&gt;jquery-contextmenu&lt;/EM&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;using:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;npm i jquery-contextmenu
npm i @types/jquery.contextmenu&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;and adding the javascript using:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;this.contextmenuScript = d3.select(this.element).append('script');
this.contextmenuScript.attr({
	type: 'text/javascript',
	class: 'showcase'
});
this.contextmenuScript.text("$(function() { $.contextMenu({ selector: '.context-menu-one', callback: function(key, options) { var m      ...&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;I get the following&amp;nbsp;error: '&lt;/SPAN&gt;&lt;SPAN&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;&lt;EM&gt;VM3309:1 Uncaught TypeError: $.contextMenu is not a function&lt;/EM&gt;&lt;/FONT&gt;&lt;/STRONG&gt;'&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Do I need to import the javascript explicitly? If so, how?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What is the correct way to add the context menu code above?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am using PBIVIZ v3.1.2 / ES6.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/swisnl/jQuery-contextMenu" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;Github&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Working example in &lt;A href="https://jsfiddle.net/phpdeveloperrahul/eraLr0z8/" target="_blank" rel="noopener"&gt;JSFiddle&lt;/A&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks for any help.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Martijn&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Jul 2019 02:41:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/jquery-contextmenu-in-custom-visual/m-p/733116#M19892</guid>
      <dc:creator>Blaenzo</dc:creator>
      <dc:date>2019-07-06T02:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: jquery-contextmenu in custom visual</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/jquery-contextmenu-in-custom-visual/m-p/733492#M19894</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;In your linked snippet, you have the following, which loads the JS libraries of interest:&lt;/P&gt;&lt;PRE&gt;&amp;lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src="https://swisnl.github.io/jQuery-contextMenu/dist/jquery.contextMenu.js" type="text/javascript"&amp;gt;&amp;lt;/script&amp;gt;&lt;/PRE&gt;&lt;P&gt;Using &lt;FONT face="courier new,courier"&gt;npm&lt;/FONT&gt; to import packages sets them up as a dependency, but does not load them; you have to do something similar in your code when/where you want to make use of them.&lt;/P&gt;&lt;P&gt;If you're using ES6, then &lt;A href="https://www.freecodecamp.org/news/how-to-use-es6-modules-and-why-theyre-important-a9b20b480773/" target="_self"&gt;have a look at how ES6 imports work&lt;/A&gt;. You will see similar statements at the top of your visual.ts for the standard stuff the visual is loading in, e.g.:&lt;/P&gt;&lt;PRE&gt;import '@babel/polyfill';
import './../style/visual.less';
import powerbi from 'powerbi-visuals-api';
import VisualConstructorOptions = powerbi.extensibility.visual.VisualConstructorOptions;
import VisualUpdateOptions = powerbi.extensibility.visual.VisualUpdateOptions;
...&lt;/PRE&gt;&lt;P&gt;The bottom two are extensions of the third line, but one that dependency has been imported then it can be referenced to specify others as simpler variables.&lt;/P&gt;&lt;P&gt;There's instructions on how to include jQuery in your project on &lt;A href="https://www.npmjs.com/package/jquery" target="_self"&gt;jQuery's NPM site&lt;/A&gt;. The section you want will be under Babel (notice that &lt;FONT face="courier new,courier"&gt;import '@babel/polyfill'&lt;/FONT&gt; above?), specifically:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;A href="http://babeljs.io/" rel="nofollow" target="_blank"&gt;Babel&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;is a next generation JavaScript compiler. One of the features is the ability to use ES6/ES2015 modules now, even though browsers do not yet support this feature natively.&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;import $ from "jquery";&lt;/PRE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;You can then access &lt;FONT face="courier new,courier"&gt;$&lt;/FONT&gt; as an object in your &lt;FONT face="courier new,courier"&gt;visual.ts&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;I'd recommend changing this slightly, as if you install the typings for jQuery (&lt;FONT face="courier new,courier"&gt;npm i&amp;nbsp;@types/jquery&lt;/FONT&gt;) then it doesn't like &lt;FONT face="courier new,courier"&gt;$&lt;/FONT&gt; as a reference (the module exports a variable named &lt;FONT face="courier new,courier"&gt;jQuery&lt;/FONT&gt; rather than &lt;FONT face="courier new,courier"&gt;$&lt;/FONT&gt;), and it's generally advisable to use the following:&lt;/P&gt;&lt;PRE&gt;import * as jQuery from 'jquery';
import 'jquery-contextmenu';&lt;/PRE&gt;&lt;P&gt;...and then referring to &lt;FONT face="courier new,courier"&gt;jQuery&lt;/FONT&gt; rather than &lt;FONT face="courier new,courier"&gt;$&lt;/FONT&gt; in your code, e.g.:&lt;/P&gt;&lt;PRE&gt;jQuery(function () {
    jQuery.contextMenu({
        ...
    })
});&lt;/PRE&gt;&lt;P&gt;I've walked this through and the libraries load (and have tested that &lt;FONT face="courier new,courier"&gt;jQuery.contextMenu&lt;/FONT&gt; exists), so you will no longer get the errors you were getting. However, I don't really use this library, so can't advise further on how you'll use it in your visual, but hopefully this will help you a bit.&lt;/P&gt;&lt;P&gt;Of note, &lt;A href="https://microsoft.github.io/PowerBI-visuals/tutorials/building-bar-chart/adding-context-menu-to-the-bar/" target="_self"&gt;the API supports a context menu as well&lt;/A&gt;, so you could also try this (personally haven't used it yet).&lt;/P&gt;&lt;P&gt;Good luck!&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jul 2019 20:55:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/jquery-contextmenu-in-custom-visual/m-p/733492#M19894</guid>
      <dc:creator>dm-p</dc:creator>
      <dc:date>2019-07-07T20:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: jquery-contextmenu in custom visual</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/jquery-contextmenu-in-custom-visual/m-p/734500#M19904</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/397"&gt;@dm-p&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That works! The import statement indeed did the trick:&lt;/P&gt;&lt;PRE&gt;import 'jquery-contextmenu';&lt;/PRE&gt;&lt;P&gt;In addition I had to add the corresponding stylesheet using:&lt;/P&gt;&lt;PRE&gt;import "./../node_modules/jquery-contextmenu/dist/jquery.contextMenu.css";&lt;/PRE&gt;&lt;P&gt;And I agree, using jQuery is much more elegant than using $:&lt;/P&gt;&lt;PRE&gt;jQuery(function () {
    jQuery.contextMenu({
        ...
    })
});&lt;/PRE&gt;&lt;P&gt;Thanks again, very much appreciated!&lt;/P&gt;&lt;P&gt;Martijn&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2019 19:55:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/jquery-contextmenu-in-custom-visual/m-p/734500#M19904</guid>
      <dc:creator>Blaenzo</dc:creator>
      <dc:date>2019-07-08T19:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: jquery-contextmenu in custom visual</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/jquery-contextmenu-in-custom-visual/m-p/734536#M19906</link>
      <description>&lt;P&gt;Sweet! Glad you're unblocked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2019 20:37:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/jquery-contextmenu-in-custom-visual/m-p/734536#M19906</guid>
      <dc:creator>dm-p</dc:creator>
      <dc:date>2019-07-08T20:37:09Z</dc:date>
    </item>
  </channel>
</rss>

