i want to be able to continue editing/inserting a row after a server error, and maintain the data already inserted. Is it possible? If so, how can i accomplish this?
Right now i can do some stuff on a server side error thru the event Error on DataSource, calling a user defined javascript function. I'm showing a popup with the error, but then the row exits the edition mode.
I can cancel UI changes but then i lose the data. If i don't cancel UI changes on the grid, the row is shown as if there were no errors, but it was not saved on the server.
Thanks in advance
13 Answers, 1 is accepted
Basically when there are server side errors you can use the approach from this code library article(related to the MVC wrappers, anyway the idea remains the same).
If there is a server side error , prevent the rebinding of the Grid so the Grid remains in edit mode and the users can correct the problem.
function error(args) {
if (args.errors) {
var grid = $("#Grid").data("kendoGrid");
grid.one("dataBinding", function (e) {
e.preventDefault(); // cancel grid rebind if error occurs
//...
Kind Regards,
Petur Subev
Telerik
Hi Petur,
This has stopped working in 2016.2.504. Any idea?
Thanks,
Jawad
Hello Kavitha,
Could you please provide a bit more information about what exactly does not work with the mentioned code library. I'm not able to observe any issue when the code library is modified to use the latest UI for ASP.NET MVC latest official release.
Regards,Rosen
Telerik
Here sample from my code
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Events(events =>
{
events.Error("kendoGridError");
})
function kendoGridError(args, ) {
if (args.errors) {
var grid = $("#users").data("kendoGrid");
grid.one("dataBinding", function (e) {
// prevent default doesn't work in 2016.2.504
e.preventDefault(); // cancel grid rebind if error occurs
});
}
}
e.preventDefault() doesn't prevent closing of the edit popup after I've upgraded to 2016.2.504
Hello Kavitha,
You should verify that the actual code path is hit - does the grid.one("dataBinding", function (e) { is executed. Also you should check if you are not manually rebinding the widget - for example by calling DataSource's read/fetch/query methods or Grid's refresh method.
If you continue to experience difficulties you should modify the Code Library project as the behavior to appear and send it back to us for further investigation.
Rosen
Telerik
It was dataSource.read(). Fixed it now.
Thanks for your help Rosen.
I updated Kendo framework to 2017.3.1026
It looks like it is not working. I am able to debug and see it is executing the code line also iam getting alert messages.
grid.one("dataBinding", function (e) {
e.preventDefault(); // cancel grid rebind if error occurs
for (var error in args.errors) {
alert("for alert" + error);
}
});
I updated the provided example to the 2017.3.1026 version and it is still working as expected.
I attached it for reference.
Regards,
Stefan
Progress Telerik
Thanks for the response
I see that project is not using 2017.3.1026, it is using 2017.3.1018.
please recheck and verify.
Thanks
Raj
However in the console log(e),
action in your example is shown as sync. (action:"sync")
In my project it shows as rebind. (action:"rebind") see attached images for console.log(e)
Thanks
Raj
Thank you for the details.
The action will be "rebind" in cases if the Grid is programmatically refreshed without making any actual changes or the when the Read of the Grid is called. Ensure that an actual update operation is made when testing the scenario.
Still, the type is not directly used in this scenario and should not affect the result.
If the issue still occurs, please provide an example where the issue is reproduced and I will gladly assist.
Regards,
Stefan
Progress Telerik
Hello,
I am also struggling with this problem in 2019.2.514.
The error function does work. The edit form remains if a server error is detected. That's nice.
However, when the button 'save' is pressed again without any changes, no server call is done and the form closes.
I understand you write 'Ensure that an actual update operation is made when testing the scenario', so can I disable the save button and enable it when someone changes a value in the edit form? Or is there another solution available?
Richard
If you would like to disable the Save button when an error from the server-side is returned, I would recommend to disable the button in the Error event handler. After that, you would be able to subscribe to the change events of the inputs within the form.
When a change in those inputs is present, enable the button once again. However, if you would like to make the editing more specific, you can attach the change event only to the field responsible for triggering the exception.
As per the case that the form getting closed after pressing the button twice, it is unexpected behavior. Is it possible for you to provide a sample project in which this issue could be observed?
Best regards,
Tsvetomir
Progress Telerik