This is a migrated thread and some comments may be shown as answers.

Dynamically add new target for an existing contextmenu

4 Answers 610 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 1
Veteran
Ron asked on 19 Dec 2016, 10:57 AM
I have a contextmenu that is targetting elements with a certain class, for example: $('#menu').kendoContextMenu(target: '.my-class'). Now I adding new DOM elements dynamically after creation of the contextmenu that have the class 'my-class'. How can I reuse the existing contextmenu?

4 Answers, 1 is accepted

Sort by
0
Dimiter Topalov
Telerik team
answered on 21 Dec 2016, 10:29 AM
Hi Ron,

The target option specifies the existing DOM elements the ContextMenu should open on. When new elements are created dynamically, you can reset the ContextMenu target via the setOptions() method, e.g.:

http://dojo.telerik.com/oruWE

I hope this helps.

Regards,
Dimiter Topalov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Ron
Top achievements
Rank 1
Veteran
answered on 21 Dec 2016, 10:46 AM

Hi Dimiter,

Works like a charm. Too bad things like these are a bit hard to find in the documentation. Thank god for the forums.

Thanks,
Ron

0
Ron
Top achievements
Rank 1
Veteran
answered on 09 Mar 2018, 03:13 PM

Hi Dimiter, allthough the proposed solution does work functionally, I am experiencing a problem. Some of my context menu's are rather large (thousands of items). Without going into the discussion if having such a large amount of items is a good idea, I noticed that by calling the proposed setOptions method, the entire component seems to be re-initialized. This results in an unacceptable long wait time for the contextmenu to be responsive after each call to setOptions. I managed to come up with a workaround but unfortunately I have to call some internal code from the contextmenu component, which is obviously not ideal. Any thoughts of a better solutions or if it's really necessary for the contextmenu to re-init after a call to setOptions only to change the target? 

Work around, see: http://dojo.telerik.com/eVUCuWat/2

0
Veselin Tsvetanov
Telerik team
answered on 13 Mar 2018, 12:26 PM
Hi Ron,

I have carefully reviewed the implementation of the setOptions() method of the ContextMenu and the widget as a whole and have performed several test. Nevertheless, I did not managed to reproduce a scenario in which the ContextMenu gets re-initialized (executes its init() method) after the setOptions() has been called. May I ask you to prepare and send us such sample, where the described could be observed?

As per the _wire() method call, it does exactly what you need. It will reattach the required listeners to the target elements. As you have correctly noted, using internal methods is never the best option. Nevertheless, in this specific case it executes the appropriate logic.

Regards,
Veselin Tsvetanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Menu
Asked by
Ron
Top achievements
Rank 1
Veteran
Answers by
Dimiter Topalov
Telerik team
Ron
Top achievements
Rank 1
Veteran
Veselin Tsvetanov
Telerik team
Share this question
or