This is a migrated thread and some comments may be shown as answers.
Client side Delete using ContextMenu
2 Answers 49 Views
This is a migrated thread and some comments may be shown as answers.
Datamex
Top achievements
Rank 2
Datamex asked on 10 Aug 2009, 01:49 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Schlurk
Top achievements
Rank 2
answered on 12 Aug 2009, 01:47 PM
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.





0
Datamex
Top achievements
Rank 2
answered on 13 Aug 2009, 06:33 AM
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!
Tags
Grid
Asked by
Datamex
Top achievements
Rank 2
Answers by
Schlurk
Top achievements
Rank 2
Datamex
Top achievements
Rank 2
Share this question
or