dynamic add item in context menu by javascript

5 posts, 0 answers
  1. Piyush Vardhan
    Piyush Vardhan avatar
    8 posts
    Member since:
    May 2008

    Posted 22 May 2008 Link to this post

    Hello Friends
    How Can i  dynamic add  item in context menu  and open Context Menu  on Grid row click by javascript .
  2. Erjan Gavalji
    Admin
    Erjan Gavalji avatar
    1455 posts

    Posted 22 May 2008 Link to this post

    H Piyush,

    Please check the AJAX-enabled context menu in grid for an example of how to create a context menu for RadGrid and the Add, remove, disable menu items for a demonstration of the client-side RadMenu API, related to item management.

    I hope this helps.

    Kind regards,
    Erjan Gavalji
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Piyush Vardhan
    Piyush Vardhan avatar
    8 posts
    Member since:
    May 2008

    Posted 22 May 2008 Link to this post

    Thanks For Reply Friend
    I want when i click or right click on row of grid then context menu  open with value  of(
    QuantityPerUnit UnitPrice UnitsInStock
    ) in context Menu through Ajax or Javascript .i want dinamic Context menu which Create on click of grid row. r u getting  me what i want? i
  5. Jorge Gracia
    Jorge Gracia avatar
    6 posts
    Member since:
    Nov 2009

    Posted 01 Aug 2012 Link to this post

    I have a very similar need.

    Require a context menu were its items change based on where the users right clicks.
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 02 Aug 2012 Link to this post

    Hello,

    I suppose you want to show different RadContextMenu for different target controls. Following is the sample code.

    ASPX:
    <telerik:RadButton ID="RadButton1" runat="server" AutoPostBack="false">
    </telerik:RadButton>
    <telerik:RadButton ID="RadButton2" runat="server" AutoPostBack="false">
    </telerik:RadButton>
    <telerik:RadButton ID="RadButton3" runat="server" AutoPostBack="false">
    </telerik:RadButton>
    <telerik:RadContextMenu ID="RadContextMenu1" runat="server" OnClientShown="OnClientShown"  >
      <Targets>
        <telerik:ContextMenuControlTarget ControlID="RadButton1" />
        <telerik:ContextMenuControlTarget ControlID="RadButton2" />
        <telerik:ContextMenuControlTarget ControlID="RadButton3" />
      </Targets>
    </telerik:RadContextMenu>

    JS:
    <script type="text/javascript">
        function OnClientShown(sender, args) {
            var k = sender.get_items().get_count();
            for (i = 0; i <= k; i++) {
                sender.trackChanges();
                sender.get_items().removeAt(0);
                sender.commitChanges();
            }
            if (args.get_targetElement().name == "RadButton1") {
                var item1 = new Telerik.Web.UI.RadMenuItem();
                item1.set_text("item1");
                var item2 = new Telerik.Web.UI.RadMenuItem();
                item2.set_text("item2");
                var item3 = new Telerik.Web.UI.RadMenuItem();
                item3.set_text("item3");
                sender.trackChanges();
                sender.get_items().add(item1);
                sender.get_items().add(item2);
                sender.get_items().add(item3);
                sender.commitChanges();
            }
            else if (args.get_targetElement().name == "RadButton2") {
                var item1 = new Telerik.Web.UI.RadMenuItem();
                item1.set_text("item4");
                var item2 = new Telerik.Web.UI.RadMenuItem();
                item2.set_text("item5");
                var item3 = new Telerik.Web.UI.RadMenuItem();
                item3.set_text("item6");
                sender.trackChanges();
                sender.get_items().add(item1);
                sender.get_items().add(item2);
                sender.get_items().add(item3);
                sender.commitChanges();
            }
            else if (args.get_targetElement().name == "RadButton3") {
                var item1 = new Telerik.Web.UI.RadMenuItem();
                item1.set_text("item7");
                var item2 = new Telerik.Web.UI.RadMenuItem();
                item2.set_text("item8");
                var item3 = new Telerik.Web.UI.RadMenuItem();
                item3.set_text("item9");
                sender.trackChanges();
                sender.get_items().add(item1);
                sender.get_items().add(item2);
                sender.get_items().add(item3);
                sender.commitChanges();
            }
        }
    </script>

    Hope this helps.

    Regards,
    Princy.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017