ClientDetailTemplate - Update Handler

2 Answers 130 Views
Grid
CPS
Top achievements
Rank 1
Iron
Iron
CPS asked on 08 Mar 2023, 03:40 PM

I got a grid that displays orders and details

This is the main grid:

@(
          Html.Kendo().Grid<BoWeb.Web.Models.OrderModel>().Name("gridOrders")
            .Sortable()
            .Scrollable()
            .Columns(cols =>{
              cols.Bound(col => col.OrderNr);
              cols.Bound(col => col.CreateDate).Format("{0:dd.MM.yyyy hh:mm}");
              cols.Bound(col => col.PaymentResource);
              cols.Bound(col => col.ShippingResource);
              cols.Bound(col => col.ShippingSurcharge);
              cols.Bound(col => col.TotalIncl);
            })
            .ClientDetailTemplateId("tmplOrderItem")
            .DataSource(ds => ds
              .Ajax()
              .Read(r => r.Url("/Customer/Admin?handler=ReadOrders").Data("forgeryToken"))
              .Model(m =>{
                m.Id(id => id.PKOrder);
              })
            )
            .Deferred()
        )

This works fine.

The template looks like this:

<script id="tmplOrderItem" type="text/kendo-tmpl">
  @(
    Html.Kendo().Grid<BoWeb.Web.Models.OrderItem>().Name("gridCart_#=PKOrder#")
      .Sortable()
      .Editable(edit => edit.Mode(GridEditMode.InLine))
      .Columns(cols =>{
        cols.Bound(col => col.Quantity).EditorTemplateName("IntegerEditor");
        cols.Bound(col => col.Caption);
        cols.Bound(col => col.SinglePriceIncl);
        cols.Bound(col => col.TotalPriceIncl);
        cols.Command(col =>
        {
          col.Edit().Text(" ").UpdateText(" ").CancelText(" ");
        }).Width(120);
      })
      .DataSource(ds => ds
        .Ajax()
        .Read(r => r.Url("/Customer/Admin?handler=ReadOrderItems&orderId=#=PKOrder#").Data("forgeryToken"))
        .Update(u => u.Url("/Customer/Admin?handler=UpdateOrderItem").Data("forgeryToken"))
        .Model(m =>
        {
          m.Id(id => id.FKSubItem);
          m.Field(f => f.Quantity);
          m.Field(f => f.Caption).Editable(false);
          m.Field(f => f.SinglePriceIncl).Editable(false);
          m.Field(f => f.TotalPriceIncl).Editable(false);
        })
      )
      .ToClientTemplate()
  )
</script>

The read works. No problem and data is displayed correctly.

But the update-handler is not called.

The handler looks like this:

public JsonResult OnPostUpdateOrderItem([DataSourceRequest]DataSourceRequest request, OrderItem item)
    {
      if(item != null && ModelState.IsValid)
      {

      }
      return new JsonResult(new[] { item }.ToDataSourceResult(request, ModelState));
    }

I also inject Xsrf and added 

@Html.AntiForgeryToken()

Of course there is also the

@Html.Kendo().DeferredScripts()

Any ideas why this is not working?

2 Answers, 1 is accepted

Sort by
0
Aleksandar
Telerik team
answered on 13 Mar 2023, 08:40 AM

Hello CPS,

The configuration shared seems correct, so I'm not sure what is causing the reported behavior. By "But the update-handler is not called." do you mean a request is not sent at all? Or a request is made but data is not bound at the endpoint? Are there any JavaScript errors logged on the console? In addition, I would also assume the FKSubItem property of each item has a value different that the default, as noted in the requirement for the Model Id documentation section, is that correct? I tried to reproduce the behavior in a sample REPL, and if you try to edit a record in a details grid you will note a POST request sent in the network tab, as expected. The request will fail, as there is no such endpoint in the example, but a request is made nonetheless.

Regards,
Aleksandar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
CPS
Top achievements
Rank 1
Iron
Iron
answered on 15 Mar 2023, 03:42 PM

Hi Aleksandar

Thanks a lot for your answer.

The problem was the EditorTemplate.

Although the value was changed, the grid apparently did not get it and did't raise the update event.

After changing the template, everything works now like expected.

Tags
Grid
Asked by
CPS
Top achievements
Rank 1
Iron
Iron
Answers by
Aleksandar
Telerik team
CPS
Top achievements
Rank 1
Iron
Iron
Share this question
or