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

OnRadContextMenu Right Click Get Cell Index

7 Answers 142 Views
Grid
This is a migrated thread and some comments may be shown as answers.
CG
Top achievements
Rank 1
CG asked on 18 May 2011, 06:17 PM
Hello,

I am trying to get the column index when right clicking the radgrid to open up a context menu. target.cellindex returns as 'Undefined'.
I find that sometimes it does return the right index and at other times its undefined. 
Upon further debugging I noticed that when the index returns as undefined, the 'cellIndex' variable property is not found under the 'target' reference and is when it returns a number.

This is pretty urgent and I'd like to get a fix for this ASAP. 
Has this issue been fixed or is there a workaround?

Thanks!

Posted 12 minutes ago (permalink)

Upon further debugging I noticed that when the index returns as undefined, the 'cellIndex' variable property is not found under the 'target' reference and is when it returns a number.

This is pretty urgent and I'd like to get a fix for this ASAP. 

Posted 12 minutes ago (permalink)

Upon further debugging I noticed that when the index returns as undefined, the 'cellIndex' variable property is not found under the 'target' reference and is when it returns a number.

This is pretty urgent and I'd like to get a fix for this ASAP. 

7 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 May 2011, 07:02 AM
Hello CG,

I  am not sure about your exact requirement. One suggestion is you can access the selected row index and then you can access cell index using the property getCellByColumnUniqueName.

Javascript:
<script type="text/javascript">
function RowContextMenu(sender, args)
  {
    var menu = $find("<%=RadMenu1.ClientID %>");
  . . . . .    
    alert(args.get_itemIndexHierarchical());
 }
</script>

Thanks,
Princy.
0
CG
Top achievements
Rank 1
answered on 19 May 2011, 02:32 PM
Hi Princy,

Thanks for the response, but I'm afraid I can't approach it that way. I have a grid filled with numbers. What I want to do is have a user right click any cell which will open up a context menu with the options of "Chart Row data" or "Chart column data". When they select one of these options it will open up a radwindow with a chart and some other features. The reason why I need to get the column index (as well as the row index) is because when the radwindow opens the data from the grid is saved in a session and that specific row or column index they clicked gets passed through the URL as a parameter and is later used to retrieve data from the Session.
The only way I am able to get the column index is with the method i mentioned above. However I find that it works sporadically. I would click on the same cell several times and its pretty much like flipping a coin in terms of getting the right index or 'undefined'.

Any help is greatly appreciated.
0
Tsvetina
Telerik team
answered on 24 May 2011, 02:47 PM
Hi CG,

You could loop through the grid cells in the code-behind and attach their onmousedown client event. Then, on the client you should be able to access the target of the event and its cellIndex. Then, you could use it in the grid OnRowContextMenu event. You might need to set a timeout before executing the logic in the latter, so that you make sure that it executes second.

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
CG
Top achievements
Rank 1
answered on 24 May 2011, 02:50 PM
Thanks Tsvetina,

But is this the only work around? I can't be looping through thousands of rows and columns.
Will this bug be fixed in the future?

Thanks
0
Tsvetina
Telerik team
answered on 27 May 2011, 11:44 AM
Hello,

You can also try the following on the RowContextMenu client event:
function contextMenu(sender, eventArgs) {
    var evt = eventArgs.get_domEvent();
    alert(evt.target.cellIndex);
}


Kind regards,
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
CG
Top achievements
Rank 1
answered on 27 May 2011, 02:28 PM
Hi Tsvetina,

I tried your example and as mentioned before I sometimes would get a number to return and sometimes i get 'undefined'
0
Tsvetina
Telerik team
answered on 28 May 2011, 08:15 AM
Hi,

I assume this happens when you click on an image or other control inside the grid cells because the context menu event is attached to the row itself, not its children. If this is so on your side, you should use the parentNode property of the image node, so that you get the cell that accomodates the image and access its cell index.

All the best,
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
CG
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
CG
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or