Setting CSS from a contextmenu

Tags: #<Tag:0x00007f8b1d87f9d8> #<Tag:0x00007f8b1d87f7d0>

This is probably a javascript knowledge issue, but I"m trying to set the background colour of a cell from a submenu. But I keep getting “Cannot read properties of undefined” errors from my callback. How do I access the cell metadata from within a submenu callback?

Here is my contextmenu setup…

       build_category: { // Own custom option
            name: 'Build Category...',
            submenu: {
                // Custom option with submenu of items
                items: [
                    {
                        // Key must be in the form 'parent_key:child_key'
                        key: 'build_category:ootb',
                        name: 'ootb',
                        callback(key, selection, clickEvent) {
                            console.log(JSON.stringify(selection));
                            this.hot.setCellMeta(2, 2, 'className', 'isConfig');
                        },

                    },

Hi @denis.krizanovic

Thank you for contacting us. I think that this example will help you solve this issue: https://jsfiddle.net/handsoncode/p3ncsy45/

You can choose the color of the cell from context menu.

Thanks for the prompt reply Adrian, but my issue persists - And I think it reflect my low skills in javascript. In my situation, I am in a class, and I can not access the member variables, by using “this”, or directly accessing the “hot” member like you have. Perhaps there is another way I can get access to this member from a callback?

I’ve pasted my javascript into this fiddle -> https://jsfiddle.net/deniskrizanovic/y61vhjgf/2/ if you can take a look. It’s part of a Salesforce Lightning Web Component, but I don’t think that is material to my problem.

I also tried to wrap your fiddle with a class here -> https://jsfiddle.net/deniskrizanovic/vwuLg8fo/3/ but jsFiddle tells me it doesn’t support export keyword.

Hi @denis.krizanovic

I’m not sure if I understand the problem with using this solution inside the Class. The Salesforce example you sent has too many missing elements, so I am not able to properly test it.

It’s also worth mentioning that Handsontable doesn’t officially support Salesforce Lightning Web Component, so it might cause some issues.