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

Enable to find DataKeyValues on click in Context menu in Grid row

5 Answers 145 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jaswant Singh
Top achievements
Rank 1
Jaswant Singh asked on 26 Mar 2010, 06:23 PM

Hi

I have a RadGrid, I have now been tasked with putting a Right Click Context menu in place. What I need to figure out is:


1)     How can I get a value from the either the DataItem or the DataKeyValues from client side for the row that has fired off the
        context menu?   

    
Any thoughts / pointers most appreciated

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 29 Mar 2010, 06:36 AM

Hello Jaswant Singh,

The following client code shows how to access the DataKeyValue on right-clicking the row for showing context menu.

Client code:

 
    function RowContextMenu(sender, eventArgs) {  
        var menu = $find("<%=RadMenu1.ClientID %>");  
        var evt = eventArgs.get_domEvent();  
        var grid = $find("<%=RadGrid1.ClientID %>");  
        if (evt.target.tagName == "INPUT" || evt.target.tagName == "A") {  
            return;  
        }  
 
        var index = eventArgs.get_itemIndexHierarchical();  // Get the index  
        var dataItem = sender.get_masterTableView().get_dataItems()[index]; // Get the dataitem  
        alert(dataItem.getDataKeyValue("CustomerID"));  
     . . .  
 
    } 

Happy coding, :)

-Shinu.

0
A
Top achievements
Rank 1
answered on 18 Jan 2011, 08:52 AM
I've tried this snippet but its not working and giving me null value in return. am i missing anything?? In attached image you can see, its giving null for datakeyvalue
plus, please tell me how to enable context menu grid having cardview style, context menu doesn't appear, if i have <ItemTemplate> command in grid which overlays all columns
0
Tsvetina
Telerik team
answered on 21 Jan 2011, 08:36 AM
Hello Jaswant ,

Could you please confirm if you have specified ClientDataKeyNames in the MasterTableView declaration that list the names of the fields which you will be accessing in javascript?

Greetings,
Tsvetina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
A
Top achievements
Rank 1
answered on 24 Jan 2011, 07:24 AM
Thanks, It worked with ClientDataKeyNames :)

but you didn't answer my other question
If i m using grid in CardView Style, where all columns are overlaid by <ItemTemplate> style
then what should i do to get the right click event on that... pressing right click on itemtemplate doesnt execute the context menu event of grid
please help me out in this as well
with thanks

0
Tsvetina
Telerik team
answered on 26 Jan 2011, 04:31 PM
Hi Jaswant,

Most probably the controls that you have specified in the ItemTemplate have higher priority when firing their client events and they are bubbled instead of the grid's OnRowContextMenu event. Therefore, you would need to manually either:
-Handle the respective click event of the inner controls and show the context menu when it occurs.
-Point the controls from the template as target controls of the context menu.

I hope one of two helps you achieve the desired functionality.

Best wishes,
Tsvetina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Jaswant Singh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
A
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or