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

[Solved] How do I change a menu in a grid on a per row?

1 Answer 82 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
bbeatty
Top achievements
Rank 1
bbeatty asked on 02 Apr 2012, 06:47 PM
I'm trying to host a menu control within a cell of a telerik grid where the sub menu can change based on values in the row.
I've gotten the menu control hosted correctly.
But I'm trying to figure out how to change menu on a per row basis.

This is what I'm attempting but failing
 
if ( Model.WorkflowStatusName == "StatusX") { 
    Html.Telerik().Menu()
    .Name("Menu_<#=Id #>").HtmlAttributes(new { style = "z-order:100000000" })
    .Orientation(MenuOrientation.Vertical)
    .Items(menu => menu.Add().Text("Actions")
      .Items(sub =>
      {
        sub.Add().Text("Edit").HtmlAttributes(new { workItemId = "<#= Id #>",   action = "Edit" });       
        })
    )
    .ClientEvents(e =>e.OnSelect("OnSelect"))
  .ToHtmlString();
} else {
    Html.Telerik().Menu()
   .Name("Menu_<#=Id #>").HtmlAttributes(new { style = "z-order:100000000" })
   .Orientation(MenuOrientation.Vertical)
   .Items(menu => menu.Add().Text("Actions")
     .Items(sub =>
     {
      sub.Add().Text("Complete").HtmlAttributes(new { workItemId = "<#= Id #>",   action = "Complete" });    
     })
   )
   .ClientEvents(e =>   e.OnSelect("OnSelect"))
   .ToHtmlString();
}

Is this possible mixing the Grid and Menu?

1 Answer, 1 is accepted

Sort by
0
bbeatty
Top achievements
Rank 1
answered on 05 Apr 2012, 03:55 PM
I changed my Model to return the content for ClientTemplate
ex:
In the Model I have  property 


 public string MenuItems
        {
            get
            {
                var sb = new StringBuilder();
                if (WorkflowStatus != WorkflowStatuses.Complete )
                {
                    sb.AppendFormat("<li class=' t-item t-state-default' workItemId='{0}' action='Add' companyId = '{1}'>New</li>", Id, InsuredCompany.Id);
                    if (WorkflowStatus != WorkflowStatuses.Assigned)
                    {
                        sb.AppendFormat("<li class=' t-item t-state-default' workItemId='{0}' action='Complete' companyId = '{1}'>Complete</li>", Id, Company.Id);
                    }
                }
 
                sb.AppendFormat("<li class=' t-item t-state-default' workItemId='{0}' action='Edit' companyId = '{1}'>Edit Company</li>", Id, Company.Id);
                sb.AppendFormat("<li class=' t-item t-state-default' workItemId='{0}' action='View' companyId = '{1}'>View Company</li>", Id, Company.Id);
                return sb.ToString();
 
            }
        }
 
In the View:
 
 .Items(menu => menu.Add().Text("Actions")
                                        .Content(@<text>                                                        
                                                                     <ul class="MenuActions t-widget t-reset t-header t-menu t-menu-vertical">
                                                                       <#=MenuItems#>                                                            
                                                                     </ul>
                                                       </text>)
                                                )
                                               .ClientEvents(e =>
                                               {
                                                   e.OnOpen("WorkflowItem_MenuOnOpen");
                                                   e.OnSelect("WorkflowItem_OnSelect");
                                               })
Tags
Menu
Asked by
bbeatty
Top achievements
Rank 1
Answers by
bbeatty
Top achievements
Rank 1
Share this question
or