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

[Solved] RadGrid RadContextMenu - conditionally show items

4 Answers 370 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 28 Sep 2009, 06:25 PM
Hello,
I have a RadContextMenu attached to a RadGrid like shown in this demo: http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandmenu/defaultcs.aspx?product=grid.

I would like to be able to conditionally disable/enable items in the ContextMenu based on a data element in the Grid.  How can I do this?  For example, if a field is "true", I would like to have a specific Context Menu Item enabled - otherwise it will be disabled.

Thanks!!

4 Answers, 1 is accepted

Sort by
0
Schlurk
Top achievements
Rank 2
answered on 28 Sep 2009, 08:16 PM
I was looking around and found this post that could help you out. You would of course have to modify what the condition is that disables/enables items, but the basic structure is there.
0
John
Top achievements
Rank 1
answered on 01 Oct 2009, 01:54 PM
Interesting.  It seems the condition for that is the index of the row.  I'm looking to base the condition on a data element.  Any advice for that?  I'll hack away at the provided solution to see if I can figure it out, but if you have any guidance I would appreciate it.
0
Schlurk
Top achievements
Rank 2
answered on 01 Oct 2009, 04:07 PM
I believe the function you should take a look at would be get_element():

 
function getGridDivElement() 
  var grid= $find("<%= RadGrid1.ClientID %>"
  var gridDiv = grid.get_element(); 
}  

This should be able to allow you to play around with the particular grid element that was clicked. For more info on the client-side events/functions/properties of the RadGrid check out the documentation.
0
John
Top achievements
Rank 1
answered on 01 Oct 2009, 05:59 PM
Thanks for your help.  Here is how I got it working:

//This function handles dynamically enable/disabling and hiding/showing items in grid context menu...  
            function SetDynamicItems(menu, dataItem) {  
                //Set "Undecline Dealer" item...  
                var menuItem = menu.findItemByText("Undecline Dealer");  
 
                if (dataItem.getDataKeyValue("IsDeclined") == 'False') {  
                    menuItem.hide();  
                }  
                else {  
                    menuItem.show();  
                }  
            } 

I called this before the menu.show method so I didn't get the blinking with items appearing or disappearing after the menu was shown.  This requires the developer to declare the fields in as ClientDataKeyNames.
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Schlurk
Top achievements
Rank 2
John
Top achievements
Rank 1
Share this question
or