Dynamically add new target for an existing contextmenu

5 posts, 0 answers
  1. Ron
    Ron avatar
    70 posts
    Member since:
    Oct 2010

    Posted 19 Dec 2016 Link to this post

    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?
  2. Dimiter Topalov
    Admin
    Dimiter Topalov avatar
    770 posts

    Posted 21 Dec 2016 Link to this post

    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.
  3. Ron
    Ron avatar
    70 posts
    Member since:
    Oct 2010

    Posted 21 Dec 2016 in reply to Dimiter Topalov Link to this post

    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

  4. Ron
    Ron avatar
    70 posts
    Member since:
    Oct 2010

    Posted 09 Mar in reply to Dimiter Topalov Link to this post

    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

  5. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    724 posts

    Posted 13 Mar Link to this post

    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.
Back to Top