swisnl / jQuery-contextMenu

jQuery contextMenu plugin & polyfill
https://swisnl.github.io/jQuery-contextMenu/
MIT License
2.25k stars 744 forks source link

update specific contextMenu #676

Open Kvasha123 opened 5 years ago

Kvasha123 commented 5 years ago

I'm having the Problem, that i can't figure out how i specify a specific contextMenu that i want to update (change items to display as disabled).

You have the following functionality that i tried:

$('.context-menu-one').contextMenu('update'); // update single menu
$.contextMenu('update') // update all open menus

the second function works, but updates all menus (as said), but what selector should be used for the first function instead of $('.context-menu-one').

I tried to give the menu an class and use these class as selector, but no success.

I hope someone can help here

Kvasha123 commented 5 years ago

I would be okay with $.contextMenu('update'); but this opens the closed menus as well

bbrala commented 5 years ago

The selector should be the same as the selector that was used to initialize the contextmenu. So the selector on which the menu is bound.

Kvasha123 commented 5 years ago
$.contextMenu({
        selector:   '#ctxSelector a',
        build: function($triggerElement, e){
            return {
                callback: function(){},
                items: {
                    'item1': {
                        name: 'Item 1',
                        icon: 'fas fa-route'
                    },
                    'item2': {
                        name: 'Item 2',
                        icon: 'fas fa-draw-polygon'
                    }
                }
            }
        }
    });

So in my case, the selector would be '#ctxSelector a' ?

bbrala commented 5 years ago

Yes it should be.

Kvasha123 commented 5 years ago

It's not working. And I have no idea why. I have JSF in my Project, could that be the problem?

whilelfo commented 3 years ago

Old topic but, try this: $.contextMenu('update', { context: $.contextMenu.menus[".contextMenu2"] }); // update single menu

if you're talking about updating only the 2nd created menu,

whilelfo commented 3 years ago

Actually, It seams to have a bug at the single menu update: I've changed the line 1656 to: op.update(o.context); And so, I've called the update like this: $.contextMenu('update', { context: [$.contextMenu.menus[".contextMenu2"]] }); The array "context" is required to pass some verification's.