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

Grid after update requestEnd breaks read, update and create methods

3 Answers 922 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bruce
Top achievements
Rank 1
Bruce asked on 13 Apr 2019, 02:42 PM

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

3 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 15 Apr 2019, 01:07 PM
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.
0
Bruce
Top achievements
Rank 1
answered on 15 Apr 2019, 08:35 PM

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

0
Bruce
Top achievements
Rank 1
answered on 15 Apr 2019, 09:14 PM

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

Tags
Grid
Asked by
Bruce
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Bruce
Top achievements
Rank 1
Share this question
or