I've been trying to implement cell-based editing into my grid. It does work in a fashion, in that I can edit the current values present in the grid and they do save when clicking the Save Changes button. However, it does not appear to be firing the Update function correctly, which points to a function in the Controller. I know the grid is able to fire events for Read since I've applied a filter which uses a function in the Controller, and it's able to call that function without problems. It just doesn't seem to fire the Update function.
Below is the code for the table;
I've also found that when clicking on the Cancel Changes button that it will throw an error to the console, and subsequent attempts to navigate on the grid also throw errors.This occurs when you click the Cancel Changes button just after clicking the Save Changes button. See attached screenshot for details.
Thank you ahead of time for your assistance.
11 Answers, 1 is accepted
Thank you for the details.
I made the same Grid and it was working as expected on my end. I can assume that we are missing a detail which is overlooked at the moment.
Could you please check the network tab is a request is made from the Grid.
Also, when the item is changed from the user, is the dirty indicator is shown to indicate that the value is changed?
As the issue seems a specific one, please provide an example where it can be observed locally and I will gladly test it and made the needed modification to it.
Thank you in advance for the collaboration.
I've done a check with the Network tab open. There is a request going through, see attached screenshot for details.
The indicator is shown when changing values. As explained before, the changes are saved to the Grid, they just aren't persisting to the database and the controller function isn't being called.
Due to the nature of our work I can't provide a full program for you to look at. However I'll include some extra code I feel might be relevant to the issue.
Below is the function that is being successfully called by the Grid;
Below is the function trying to be called in the Controller (right now set to return null since I was mainly debugging to see if the function could be called).
The request that you showed in your screenshot looks like the initial load request of the View. The one made by the DataSource should be using the address specified in the Read configuration: ScheduleAdminTwo/Schedule_Read. Is there such a request in the Network tab when you load the Grid?
I cannot see anything that could be causing the described problems. I am sending you a project that I created re-using the snippets you sent us where the Update method is called successfully. You will need to re-add the Kendo.Mvc.dll to it to run it.
Could you modify the project until it starts reproducing the problem(s) that you observe in your Grid? We need to be able to reproduce the issue in order to find its cause and a fix for it.
I've tried changing the project you sent to recreate the problem but am unable to do so. I've also made some changes to my own project based on the working snippet that you sent, which includes the following;
- Refactoring all code into a single cshtml file
- Change the model used to the more simplified one (previously I've been using data annotations combined with a parent class for my models)
- Setting the filter to always return the same set of records, bypassing the filter controls entirely
- Removing the error handler code so that the function is blank
- Renaming the table to Schedule
Looking at the lines of code in the Kendo UI source code that throw the error, it seems like there is a null data item in the DataSource at the time the cancel action is triggered. But I do not know what might be causing this based on the code that you sent and I am unable to debug this at this point.
Would it be possible that you strip down your project and send it to use in a private support ticket? In this way, I will be able to debug the Grid source code at the place it fails and see what is wrong with the underlying data objects. You can create a List of dummy data in the Schedule_Read and leave Schedule_Write with no particular implementation in order to decouple the Grid implementation form your actual database and send me only the code implementation without the sensitive data. It should even be possible to copy my implementation of these methods.
I've sent a support ticket with the minimal amount of code present for you to look at.
I just replied in the support ticket which you opened but wanted to also post here in case someone else finds this thread and has a similar question.
The issue was coming from 0 values of the ID field. When the value of an item ID field (int type) equals 0, the Grid considers this item a new one and tries to fire a Create instead of an Update request. When editing a Grid, the field specified as a model Id field needs to have unique non-default values.
I hope that with this change, your Grid editing will start working as expected.
The issue was resolved in an outside ticket, but just to update this post, the issue was that I was not properly copying over the unique ID of each record. Having this attached to the records enabled me to save my edits back to the database.
Thanks for everyone's help.