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

Invoke edit controller from grid

2 Answers 156 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 13 Sep 2012, 03:39 PM
How can I invoke an edit controller from a grid?  I have tried adding a custom command with an Action("Edit","Customers") but there does not seem to be a way to pass the CustomerID to the action.  I got the javascript code from the sample custom command grom the grid demo, but I don't seem to be able to make it work.  This is what I have, but it doesn't seem to execute the click.

@model IEnumerable<LightRouteDB.Customer>
 
@{
    ViewBag.Title = "Customer List";
}
 
@(
 Html.Kendo().Grid(Model)
    .Name("CustomerGrid")
    .Pageable()
    .Sortable()
    .Filterable()
    .Columns(cols =>
    {
        cols.Bound(c => c.CustomerNum).Width(100).Groupable(false);
        cols.Bound(c => c.CustomerName).Width(200);
        cols.Bound(c => c.BillAddr1).Width(200).Title("Address");
        cols.Bound(c => c.BillCity).Width(100).Title("City");
        cols.Bound(c => c.TotalDue).Format("{0:c}").Title("Balance");
        cols.Command(cmd => cmd.Custom("Edit").Text("Edit").Click("editCustomer"));
    })
)
 
<script type="text/javascript">
    function editCustomer(e) {
        e.preventDefault();
                 
        var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
        window.nav("/customers/edit/" + dataItem.CustomerID);
    }
</script>

2 Answers, 1 is accepted

Sort by
0
John
Top achievements
Rank 1
answered on 13 Sep 2012, 04:13 PM
I found the solution:

@{
    ViewBag.Title = "Customer List";
}
 
@(
 Html.Kendo().Grid(Model)
    .Name("CustomerGrid")
    .Pageable()
    .Sortable()
    .Filterable()
    .Columns(cols =>
    {
        cols.Bound(c => c.CustomerNum).Width(100).Groupable(false);
        cols.Bound(c => c.CustomerName).Width(200);
        cols.Bound(c => c.BillAddr1).Width(200).Title("Address");
        cols.Bound(c => c.BillCity).Width(100).Title("City");
        cols.Bound(c => c.TotalDue).Format("{0:c}").Title("Balance");
        cols.Command(cmd => cmd.Custom("EditCustomer").Text("Edit").Action("Edit","Customers").DataRouteValues(v=>v.Add(c=>c.CustomerID).RouteKey("id")));
    })
)
0
Deon
Top achievements
Rank 1
answered on 05 Feb 2013, 01:23 AM
Thanks John, I have been looking for this for quite some time.
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
Deon
Top achievements
Rank 1
Share this question
or