Looking for example of associating an error in grid with a cell (or row) of server side validation

1 Answer 84 Views
Grid
Steve
Top achievements
Rank 1
Steve asked on 29 May 2021, 03:58 AM

I have a server side update service that does validations. I'd like to see an example of a failed update response message and grid config that gives an error on a field with a message. I saw some questions on this years ago in the forum as associating an error with a cell or row was not possible at the time. Hopefully that has changed.

Steve

 

1 Answer, 1 is accepted

Sort by
0
Georgi Denchev
Telerik team
answered on 02 Jun 2021, 01:12 PM

Hello, Steve,

You can use the datasource's error event and listen for errors coming from the server. If there are errors present in the response, prevent the grid from binding(this will keep the row that is currently being edited open) and show the messages.

The visualization of the errors is a customization and is up to the developer to decide where and how to display them.

Best Regards,
Georgi Denchev
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/.

Steve
Top achievements
Rank 1
commented on 02 Jun 2021, 07:23 PM

Thanks for the response. Unfortunately, that sounds overly complicated. I'm just looking for a simple way for a grid with multirow edits and a save button to show users which rows have problems and why when they try to save. I'm open to ways to achieve that. Thanks!
Georgi Denchev
Telerik team
commented on 07 Jun 2021, 10:39 AM

Hi, Steve,

Unfortunately there are no other built-in approaches which could help you achieve the desired functionality. The proper way to handle server-side errors is as I described it. Validate each one of the rows on the server, add the id of the row and the error to a key-value collection and return the collection as an error response. Finally append the errors to the appropriate rows.

Steve
Top achievements
Rank 1
commented on 11 Jun 2021, 07:06 PM

Thanks. Do you have an example of this for how an error response message might look?
Georgi Denchev
Telerik team
commented on 16 Jun 2021, 01:46 PM

Hi, Steve,

We have a blog post which showcases how to throw error messages on the server and return them back to the grid. The backend in this case is .NET MVC, however the approach would be the same with other technologies as well.

You can scroll down to the Handling Server-Side Validation Errors section which showcases the error handling function, as well as the format of the returned response from the server.

errors: {FieldName: {errors: ["Error Message returned from the server"]}}

You can include the id of the row which failed the validation and return it in the response as well. This way you'll know which record exactly threw the error and using javascript you can find the element in the grid and append the error container on it.

errors: {FieldName: {errors:[...], id: 9999}, FieldName2: {errors:[...], id:9999}}

Tags
Grid
Asked by
Steve
Top achievements
Rank 1
Answers by
Georgi Denchev
Telerik team
Share this question
or