Client side Delete using ContextMenu

3 posts, 1 answers
  1. Datamex
    Datamex avatar
    161 posts
    Member since:
    Jun 2012

    Posted 10 Aug 2009 Link to this post

    Hi,

    We are going to use your example: Link to enable client-side delete in a RadGrid.

    In the example you are deleting a record inline, but we like to do it from the contextmenu.  
    Is this possible?

    Greetings William
  2. Answer
    Schlurk
    Schlurk avatar
    812 posts
    Member since:
    May 2009

    Posted 12 Aug 2009 Link to this post

    iCe01,
    I looked around in the documentation for a bit and found the following page:
    http://www.telerik.com/help/aspnet-ajax/grdradmenuascontextmenuofradgrid.html
    It seems like there is no easy <contextmenu></contextmenu> integration with RadGrid, however, you can create a RadMenu and then through some coding have that interact with the RadGrid just like a context menu would.





  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Datamex
    Datamex avatar
    161 posts
    Member since:
    Jun 2012

    Posted 13 Aug 2009 Link to this post

    Hi,

    I found the solution.

    I used the following code to set the selectedItem of the radgrid

    function RowContextMenu(sender, eventArgs) {  
            var menu = $find("<%=UnscheduleAppointmentsRadMenu.ClientID %>");  
            var evt = eventArgs.get_domEvent();  
     
            if (evt.target.tagName == "INPUT" || evt.target.tagName == "A") {  
              return;  
            }  
     
            var index = eventArgs.get_itemIndexHierarchical();  
            document.getElementById("radGridClickedRowIndex").value = index;  
     
            sender.get_masterTableView().selectItem(sender.get_masterTableView().get_dataItems()[index].get_element(), true);  
     
            menu.show(evt);  
     
            evt.cancelBubble = true;  
            evt.returnValue = false;  
     
            if (evt.stopPropagation) {  
              evt.stopPropagation();  
              evt.preventDefault();  
            }  
          } 

    After that i delete the selected item with the following code:

    function contextMenuItemClicked(sender, args) {  
            var clickedMenuItem = args.get_item().get_value();  
            var radGridClickedRowIndex = document.getElementById("radGridClickedRowIndex").value;  
            var grid = $find('<%= UnscheduledGrid.ClientID %>');  
            var masterTableView = grid.MasterTableView;  
            var row = masterTableView.get_dataItems()[radGridClickedRowIndex];  
            var cell = masterTableView.getCellByColumnUniqueName(row, "AppointmentID");  
     
            if (clickedMenuItem == "Add") {  
              NewUnscheduledAppointment();  
            }  
            if (clickedMenuItem == "Edit") {  
              ShowAppointment(cell.innerHTML);  
            }  
            if (clickedMenuItem == "Delete") {  
              // Pop a confirmation window  
              var confirmMessage = "Delete?" 
              radconfirm(confirmMessage,  
                  function(arg) {  
                    if (arg) {  
                      // The user has confirmed deleting the appointment. So delete the appointment client side.  
                      masterTableView.deleteSelectedItems()  
                    }  
                  }, 330, 100);  
            }  
          }  
     

    Thank you!
Back to Top