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

Context menu item click this grid selected item value

4 Answers 349 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cagdas
Top achievements
Rank 1
Cagdas asked on 06 Dec 2013, 11:13 AM
Hello Telerik developers;

My problem radGrid in right click open contextMenu and context menu item click, How do I get Gird selected item value 
 How do I get RadGrid in MasterTable in GirdBoundColum CekKartID  value ? javascript code ? don't server side. did javascript code 


Html RadGrid
<telerik:RadGrid ID="grdCekKartMaster" Width="100%" Height="69%" BorderStyle="None" runat="server" AllowFilteringByColumn="false"
                    OnNeedDataSource="grdCekKartMaster_NeedDataSource">
                    <HeaderStyle BackColor="#767980" ForeColor="White" />
                    <FooterStyle BackColor="White" ForeColor="White" />
 
                    <MasterTableView runat="server" Width="100%" DataKeyNames="CekKartID" PageSize="9999">
                        <ItemStyle Font-Size="Small" Height="35" />
                        <AlternatingItemStyle Font-Size="Small" Height="35" />
                        <Columns>
                             
                            <telerik:GridBoundColumn DataField="CekKartID" HeaderText="ID" AllowFiltering="true" ReadOnly="true" ShowFilterIcon="false" Visible="false" UniqueName="CekKartID"></telerik:GridBoundColumn>                           
                            <telerik:GridBoundColumn DataField="EvrakTip" HeaderText="Evrak Tip" AllowFiltering="true" FilterControlWidth="80%" ShowFilterIcon="false" HeaderStyle-Width="100px"></telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="CekDurum" HeaderText="Çek Durum" AllowFiltering="true" FilterControlWidth="80%" ShowFilterIcon="false" HeaderStyle-Width="100px"></telerik:GridBoundColumn>                          
 
                        </Columns>
                    </MasterTableView>
                    <ClientSettings>
                        <ClientEvents OnRowContextMenu="RowContextMenu" />
                        <Selecting AllowRowSelect="true" />
                        <Scrolling AllowScroll="false"></Scrolling>
                    </ClientSettings>
 
                </telerik:RadGrid>



Html Context Menu
<telerik:RadContextMenu ID="RadMenu1" runat="server"
           EnableRoundedCorners="true" EnableShadows="true" OnClientItemClicked="rightClickHandler">
           <Items>
               <telerik:RadMenuItem Text="Add" Value="add">
               </telerik:RadMenuItem>
               <telerik:RadMenuItem Text="Edit" Value="edit">
               </telerik:RadMenuItem>
               <telerik:RadMenuItem Text="Delete" Value="delete">
               </telerik:RadMenuItem>              
           </Items>
       </telerik:RadContextMenu>


JavaScript
function rightClickHandler(sender, args) {                 
 
                    var menuItemValue = args.get_item().get_value();
 
                    if (menuItemValue == "add") {
                        alert("add click");                      
                    }
                    else if (menuItemValue == "edit") {
                        alert("edit click");
                    }
                    else if (menuItemValue == "delete") {
                        alert("delete click");
                    }
 
 
                }




4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 06 Dec 2013, 11:49 AM
Hi ,

You can get the selected row ID in the OnRowContextMenu function as follows:

JS:
function RowContextMenu(sender, eventArgs) {  
 . . . . . .
 sender.get_masterTableView().selectItem(sender.get_masterTableView().get_dataItems()[index].get_element(), true);
 
   //Get the selected row ID
 var selectedRow = sender.get_masterTableView().get_selectedItems()[0];
 var Id= sender.get_masterTableView().getCellByColumnUniqueName(selectedRow, "CekKartID").innerHTML;
    
 menu.show(evt);   
 . . . . . . .
}

Note, that with this approach the columns should be rendered. If you want to make them invisible, you should set their Display property to false. In your case set Display=false for the CekKartID column and not visible="false".

Thanks,
Princy
0
Cagdas
Top achievements
Rank 1
answered on 06 Dec 2013, 12:04 PM
function RowContextMenu(sender, eventArgs) {
                     
                    var menu = $find("<%=RadMenu1.ClientID %>");
                    var evt = eventArgs.get_domEvent();
 
                    sender.get_masterTableView().selectItem(sender.get_masterTableView().get_dataItems()[index].get_element(), true);
 
                    //Get the selected row ID
                    var selectedRow = sender.get_masterTableView().get_selectedItems()[0];
                    var Id = sender.get_masterTableView().getCellByColumnUniqueName(selectedRow, "CekKartID").innerHTML;
 
                    menu.show(evt);
 
                    //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();
                    }
 
                     
                }


your javascript code add and grid in right click default context menu open, not Radcontext menu open
0
Princy
Top achievements
Rank 2
answered on 09 Dec 2013, 05:18 AM
Hi,

Please have a look into the following JavaScript.

JS:
function rightClickHandler(sender, args) {
        var grid = $find("<%=grdCekKartMaster.ClientID %>");
        var selectedRow = grid.get_masterTableView().get_selectedItems()[0];
        var productName = grid.get_masterTableView().getCellByColumnUniqueName(selectedRow, "OrderID").innerHTML;
        alert(productName);
    }

Thanks,
Princy.
0
Cagdas
Top achievements
Rank 1
answered on 09 Dec 2013, 09:21 AM
Thanks , code worked for me 
Tags
Grid
Asked by
Cagdas
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Cagdas
Top achievements
Rank 1
Share this question
or