Invoke edit controller from grid

3 posts, 0 answers
  1. John
    John avatar
    8 posts
    Member since:
    Sep 2012

    Posted 13 Sep 2012 Link to this post

    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. John
    John avatar
    8 posts
    Member since:
    Sep 2012

    Posted 13 Sep 2012 Link to this post

    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")));
        })
    )
  3. Deon
    Deon avatar
    1 posts
    Member since:
    Jan 2013

    Posted 04 Feb 2013 Link to this post

    Thanks John, I have been looking for this for quite some time.
Back to Top