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

Question about Command Column in Grid

1 Answer 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jing
Top achievements
Rank 1
Jing asked on 03 Jul 2012, 03:17 AM
Hi

I am using Telerik MVC extension version 2012.1.419.340 (trial). I had a problem with Command Column in Grid. I will use the example code on your website to explain my problem.

I have view like:

@model IEnumerable<Order>
@(Html.Telerik().Grid(Model)
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(o => o.OrderID).Width(100);
        columns.Bound(o => o.ShipAddress);
        columns.Command(commands => commands
                    .Custom("viewDetails")
                    .Text("View Details")
                    .DataRouteValues(route => route.Add(o => o.OrderID).RouteKey("orderID"))
                    .Ajax(true)
                    .Action("ViewDetails", "Grid"))
                .HtmlAttributes(new { style = "text-align: center" })
                .Width(150);
    })
    .ClientEvents(events => events.OnComplete("onComplete"))
    .DataBinding(dataBinding => dataBinding.Ajax().Select("_CustomCommand", "Grid"))
    .Pageable()
    .Sortable()
    .Filterable()
)

and my Order model like

public class Order{
  public int OrderID {get;set;}
 
  public string ShipAddress {get ; set; }
 
  public bool CanEdit {get; set;}
}

I would like my Command Column to use different Action depending on CanEdit value. For example, if CanEdit  is false, using action
columns.Command(commands => commands
                    .Custom("viewDetails")
                    .Text("View Details")
                    .DataRouteValues(route => route.Add(o => o.OrderID).RouteKey("orderID"))
                    .Ajax(true)
                    .Action("ViewDetails", "Grid"))
                .HtmlAttributes(new { style = "text-align: center" })

if CanEdit  is true, using action
columns.Command(commands => commands
                    .Custom("editDetails")
                    .Text("Edit Details")
                    .DataRouteValues(route => route.Add(o => o.OrderID).RouteKey("orderID"))
                    .Ajax(true)
                    .Action("EditDetails", "Grid"))
                .HtmlAttributes(new { style = "text-align: center" })

Can you give me some idea how to implement it?

Thanks

1 Answer, 1 is accepted

Sort by
0
Pechka
Top achievements
Rank 1
answered on 05 Jul 2012, 12:48 PM
Hi mate,

You cannot change the route of the custom command on the fly.
If you using template column you will have more control over the request you perform and achieve your goal easier.
Tags
Grid
Asked by
Jing
Top achievements
Rank 1
Answers by
Pechka
Top achievements
Rank 1
Share this question
or