Reinitialize or check to see if menu is initialized

509 views Asked by At

I am having an issue where I initialize the context menu on a grid, and it works but I have another function on the page that when clicked hides the grid, when I bring the grid back the menu no longer works, I am thinking that maybe re-initializing it will fix my problem.

How would I reinitialize the menu? If there is no "reinitialize" function than how can I check to see if the menu has been made before I destroy it and make another?

I know I can destroy it but I cant figure out how to tell if it is initialized first?

JS:

if(order.contextmenu("initialized"))
    order.contextmenu("destroy");
2

There are 2 answers

0
Devnsyde On BEST ANSWER

I was not able to fix this or figure it out, so I removed the context menu plugin and went with another plugin author who had good documentation (link below):

http://swisnl.github.io/jQuery-contextMenu/

1
mar10 On

The menu can be (re)initialized - like any jQuery UI widget - by calling

$(selector).contextmenu({...})

but normally this should not be necessary:

If the grid was only hidden (but not removed), the menu should simply keep working as soon as the grid is made visible again.

If the grid is removed and re-created, then the selector should match some parent element that is not removed, for example like this:

$(document).contextmenu({
    delegate: ".grid-cell",
    ...
})

Then again the menu will keep working.