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

Server Validation of Grid

2 Answers 493 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 18 Oct 2015, 04:40 PM

I am having a play around with the grid.  I have implemented the following example where batch update/create/delete from this post kendo-grid-batch-incell-save-changes-with-single-trigger-for-create-update-destroy.  This works nicely where I get the rows being created/updated/deleted.

However, if I need to do some custom server side validation in a save event before the changes are committed - if there are any errors, is it possible to return the errors and set them back in the grid supposing my save send handler is:

function sendSaveAllData() {
            var grid = $('#mygrid').data("kendoGrid");
            var finalData = ...;
 
            // send the data with one request to the server
            $.ajax({
                url: "@Url.Action("SaveAllBatchChanges", "MyController")",
                data: finalData,
                type: "POST",
                error: function () {
                    //Handle the server errors
                },
                success: function (data) {
                    //alert("update on server is completed");
 
                    showMessage('success', 'My Batch', 'Successfully saved batch changes.')
 
                    //refresh the grid
                    grid.dataSource._destroyed = [];
                    grid.dataSource.read();
                }
            })
        }

With controller method:

public ActionResult SaveAllBatchChanges(
            [Bind(Prefix = "updated")]List<BatchEditModel> updated,
            [Bind(Prefix = "new")]List<BatchEditModel> created,
            [Bind(Prefix = "deleted")]List<BatchEditModel> destroyed)
        {
 
            // do some validation before notifying server
            // save if valid
 
            return Json("Success!");
        }

At the minute I show a popup message to the user which reads success - but I haven't got any code in place currently to do the validate until I find something concrete to put in place.

Ideally I want to set cell style of errors in the grid if possible back in the browser - ie red background colour if the cell contains an error. 

Is there a way to manually set error messages in the grid (client side) and highlight the error cells from an external ajax post?

Thanks

Andez

 

2 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 21 Oct 2015, 08:21 AM
Hi Andez,

Please note that the linked solution is a custom one and therefor the developer is entirely responsible for further customizing and supporting it. Currently I could only suggest to check the "GridInCellEditWithServerValidation" demo available in the following forum post for example of how to find given row and apply red borders to notify the user about the server error. 


Regards,
Vladimir Iliev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Paul
Top achievements
Rank 1
answered on 21 Oct 2015, 10:30 PM
Looks good thanks.  Will check it out
Tags
Grid
Asked by
Paul
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Paul
Top achievements
Rank 1
Share this question
or