ce
ce copied to clipboard
context menu specific item styling when clicked/toggled
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.
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)
})
}
}