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

Hide/Show Certain RadGrid Context Menu Items

4 Answers 444 Views
Grid
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 28 Nov 2012, 04:49 PM
Hi there, I have a context menu showing when the radgrid is right clicked which displays options "email user", "email mass users", "email users who have finished".

I have a radgrid which is populated with data which shows whether users have started or not started their courses. I have a column called "HasStarted" which displays false and true depending on whether or not they have started. When I right click on a row which has "HasStarted" as false I want "email user", "email mass users" to appear in the context menu and when I click on a row which has "HasStarted" as true I want "email users who have finished" to only appear in the context menu. The context menu works and the items run the correct cases just not sure how to hide and show certain items depending on the item clicked on. Any help will be appreciated thanks.


4 Answers, 1 is accepted

Sort by
0
James
Top achievements
Rank 1
answered on 29 Nov 2012, 04:05 PM
Is this not possible to do for radgrids?
0
Eyup
Telerik team
answered on 03 Dec 2012, 11:01 AM
Hi James,

You could achieve your described scenario by canceling or configuring the menu display according to the cell's content. I have created a sample RadGrid web site where I implemented the described approach. The context menu is only being displayed for the Freight column with value greater than 50 and is being populated with new items depending on the clicked cell.

Please check out the attached application and try to make best avail out of it according to your specific scenario.

In addition, you could give a look at the following demo which demonstrates creating and adding menu items on client-side:
 Menu / Add/Remove/Disable Items

I hope this will prove helpful. Please give it a try and let me know about the result.

Kind regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
James
Top achievements
Rank 1
answered on 03 Dec 2012, 11:21 AM
Your method only shows the context menu when the column I am checking has been clicked on. I still want the context menu to show wherever the row is clicked on. Also how do I interact with the new items created in the javascript in the C# page?
0
James
Top achievements
Rank 1
answered on 03 Dec 2012, 04:09 PM
No worried found the fix. You need to add OnClientMenuShowing to the radcontextmenu for your radgrid and use this javascript:
function menuShowing(sender, args) {
             var columns = $find("<%=ResultsGrid.ClientID %>").get_masterTableView().get_columns();
             var radGrid = $find("<%=ResultsGrid.ClientID %>");
             var MasterTable = radGrid.get_masterTableView();
             var selectedRows = MasterTable.get_selectedItems();
             var el = args.get_targetElement();
             var started = "";
             for (var i = 0; i < selectedRows.length; i++) {
                 var selectedRow = selectedRows[i];
                 var id = MasterTable.getCellByColumnUniqueName(selectedRow, "HasStarted")
                 //code to do stuff here.
                 started = id.innerHTML;
             }
             if (started == "False") {
                 sender.get_items().clear();
                 var newItem = new Telerik.Web.UI.RadMenuItem();
                 newItem.set_text("Email User");
                 sender.get_items().add(newItem);
                 var newItem2 = new Telerik.Web.UI.RadMenuItem();
                 newItem2.set_text("Mass Email Users");
                 sender.get_items().add(newItem2);
             }
             if (started == "True") {
                     sender.get_items().clear();
                     var newItem3 = new Telerik.Web.UI.RadMenuItem();
                     newItem3.set_text("Started but not Finished Reminder Email");
                     sender.get_items().add(newItem3);
             }
         }

The trick was to get the selected row then to loop through the selected row and find the unique column name "HasStarted" and to get its cell value with innerHTML and equal that to a string and use the string to state which menu to show dending on whether the value is true or false for the column "HasStarted"
Tags
Grid
Asked by
James
Top achievements
Rank 1
Answers by
James
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or