Telerik asp.net MVC Extension Custom Grid Command

I’ve got a case that I want to do something after Removing Item on Shopping Cart Grid. I wanna do other action which my subtotal is outside of the grid.

so I need to passed extra data also on the action.

Using and following Telerik API for Grid.

the way how you do it is

on Telerik Grid

   1: columns.Command(commands =>
   2:        {
   3:            commands.Custom("Remove")
   4:                   .Text("Remove")
   5:                   .DataRouteValues(route => route.Add(o => o.OrderItemID).RouteKey("OrderItemID"))
   6:                   .Ajax(true)
   7:                   .Action("RemoveItemCart", "ShoppingCart").HtmlAttributes(new { style = "text-align: center" });
   8:  
   9:        });
  10:  
  11:     }).Footer(false)
  12: .ClientEvents(events => events.OnComplete("onComplete")))

On Controller Return JSON and our custom Data

   1: [HttpPost]
   2:       public JsonResult RemoveItemCart(int id)
   3:       {
   4:           var cartID=ShoppingCart.GetCartId(this.HttpContext);
   5:           ShoppingCart.RemoveFromCart(cartID, id);
   6:           var cartmodel = GetAllItems();
   7:           return Json(new {items=cartmodel.CartItems,Total = cartmodel.Total});
   8:       }

On our Javascript event which is on complete , Bind Grid manually

   1: function onComplete(e) {
   2:        if (e.name == "Remove") {
   3:            debugger;
   4:            var grid = $("#ShoppingCartGrid").data("tGrid");
   5:            grid.dataBind(e.response.items);
   6:            $('#subtotal').html(e.response.Total);
   7:        }    
   8:    }
Share this post: | | | |
Published Saturday, February 18, 2012 8:14 PM by cipto

Comments

No Comments