ce icon indicating copy to clipboard operation
ce copied to clipboard

context menu specific item styling when clicked/toggled

Open mhstreta opened this issue 6 years ago • 1 comments

Is it possible to style specific context menu item dynamically? If there is an option to add classes to specific items when clicked or toggled, so we can know currently which state it has.

I tried to check custom context menu example (https://bossanova.uk/jexcel/v4/examples/contextmenu) as well but there seems no such options for this.

mhstreta avatar Aug 20 '20 10:08 mhstreta

The context menu is recreated every time it is opened. To be able to add events and modify the style and the classes programmatically I wrote a custom one

    function overrideOpenContexMenu() {
        let originaOpen = document.getElementById('spreadsheet').jexcel.contextMenu.contextmenu.open;
        document.getElementById('spreadsheet').jexcel.contextMenu.contextmenu.open = (e, items) => {
            originaOpen(e, items);
            // the first option is 'Insert a new row before'
            let div = document.querySelector('.jcontextmenu > div:nth-of-type(1)');
            div.style.backgroundColor = 'green';
            div.addEventListener('click', e => {
                console.log('first option selected', e)
            })
        }
    }

JSFiddle

alfr3dosv avatar Aug 20 '20 23:08 alfr3dosv