Grid after update requestEnd breaks read, update and create methods

4 posts, 0 answers
  1. Bruce
    Bruce avatar
    14 posts
    Member since:
    Mar 2019

    Posted 13 Apr 2019 Link to this post

    Hi!

     

    I have a kendo grid  in my MVC project, with inline editing enabled and everything works beautifully. I use read, update and create methods on the datasource to manage the data.

    I also have a summary section on my page, so after a user edits a row, i need to update the summary and there is no "built in method" on the DataSource for this.

    So after some investigation, it seems i need to use the requestEnd event, however, as soon as i do that, the read, update and create methods stop working.

    Is there a workaround for this?

    Below is small piece of the code, I've removed some not relevant bits:

                                .DataSource(dataSource => dataSource
                                    .Ajax()
                                    .ServerOperation(false)
                                    .AutoSync(true)
                                    .Model(model => model.Id(i => i.Id))
                                    .Read(read => read.Action("Index", "InvoiceGrid", Model.SelectedVendorId))
                                    .Update(update => update.Action("UpdateGrid", "InvoiceGrid"))
                                    .Create(create => create.Action("AddInvoice", "InvoiceGrid", new { batchId = batch.batch.Id }))
                                    //.Events(ev => ev.RequestEnd("refreshSummary"))
                                    ).ToHtmlString()

    If i uncomment the Events line above, it breaks the read, update and create methods.

    Is there a workaround for this?

    Bruce

  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2466 posts

    Posted 15 Apr 2019 Link to this post

    Hello Bruce,

    Such problem could occur if there is a JavaScript error in the "refreshSummary" function or if there is no such function in the scope. Please try adding the following function in the scope of the page or if there is such function, comment its content to see if the issue will be resolved:
    <script>
      function refreshSummary(){
       
      }
    </script>

    If the error is thrown within the function, you could inspect the browser's console for the thrown JavaScript error in order to pinpoint the problematic line.


    Best Regards,
    Konstantin Dikov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Bruce
    Bruce avatar
    14 posts
    Member since:
    Mar 2019

    Posted 15 Apr 2019 Link to this post

    Hi Konstantin,

    Ok, looks like we're getting somewhere.

     

    The event is fired when if first load the page and populate the grid. So this is after the first Read event.

    Then when i edit a record, the event is not firing.

     

    Any ideas why it will fire on read and not on update?

    Thanks,

    Bruce

  4. Bruce
    Bruce avatar
    14 posts
    Member since:
    Mar 2019

    Posted 15 Apr 2019 in reply to Bruce Link to this post

    Ha,

    Never mind, i figured it out :)

    I was trying to specify a parameter to the requestEnd method, which in retrospect was a silly thing to do.

    e.g. events.RequestEnd("refreshSummary(" +batchId+")")

    So it was actually firing the event when building the grid, not the read event.

    Instead I changed it to events.RequestEnd("refreshSummary")

    Then the refreshSummary is defined as:

            function refreshSummary(e) {
                var batchId = e.response.Data[0].InvoiceBatch.Id;
                //alert(e.response.Data[0].InvoiceBatch.Id);
                $.ajax({
                    type: 'GET',
                    url: '@Url.Action("RefreshSummary","InvoiceGrid")' + '/' + batchId,
                    dataType: 'json',
                    contentType: "application/json; charset=utf-8",
                    success: function (result) {
                        //alert(JSON.stringify(result));

                    }
                });
            }

    Now everything working as expected ;)

    Cheers,

    Bruce

Back to Top