Reputation: 185
I've spent some time looking for possible solutions to this issue, and this one seems the most suitable.
The code structure in my custom visual (PowerBI, Typescript) is the following:
export class Visual implements IVisual {
private settings: VisualSettings;
private host: IVisualHost;
<...>
private hot: Handsontable;
constructor(options: VisualConstructorOptions) {
<...>
};
this.hot = new Handsontable(hotElement, hotSettings);
this.hot.addHook('modifyColWidth', function(width){
if(this === this.hot.getPlugin('dropdownmenu').menu.hotMenu)
{
return 300;
}
return width;
})
}
The last piece of code outputs an error:
Uncaught TypeError: Cannot read property 'getPlugin' of undefined
at Core.<anonymous> (<anonymous>:65781:29)
at Hooks.run (<anonymous>:10485:46)
at Core.runHooks (<anonymous>:43381:89)
at Core.getColWidth (<anonymous>:42643:22)
at Table.getColumnWidth (<anonymous>:49386:17)
at Table.getStretchedColumnWidth (<anonymous>:49396:30)
at LeftOverlay.sumCellSizes (<anonymous>:83603:33)
at Overlays.adjustElementsSize (<anonymous>:53065:69)
at Object.adjustRowsAndCols (<anonymous>:40249:37)
at Core.updateSettings (<anonymous>:41558:10)0
It seems that a hook doesn't see the intance of my visual, that's why IntelliSense doesn't offer anything for the plugin: this.hot.getPlugin('dropdownmenu').menu.hotMenu
Has anyone had the same issue? Can you assist?
Upvotes: 0
Views: 484
Reputation: 538
You need to add global hook instead of local, and check if binded instance to whom hook will be applied is a part of dropdownMenu from "hot" you've defined.
const self = this;
Handsontable.hooks.add('modifyColWidth', function (width) {
if (this === (self.hot.getPlugin('dropdownMenu').menu as Menu).hotMenu) {
return 300;
}
return width;
});
Upvotes: 2