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

Maintain Kendo Grid Edit Mode on MVC ModelState error

6 Answers 292 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Beth
Top achievements
Rank 1
Beth asked on 24 Jul 2013, 04:17 PM
Using the MVC3 wrappers for Kendo UI, my grids are wired up to Controllers for their various CRUD operations.  

In one of my models, I have a series of boolean values (that in turn handle values for checkboxes) where at least one has to be checked before being considered "valid".  As I have not found a good way to handle that kind of validation directly in the model, I am manually checking those 3 booleans in the ActionResult and where all are false, I return an error on the ModelState.  

What I would like to be able to do is when the grid receives the error in its respective event, to keep the row that was being edited in edit mode.  My attempts to put the row in edit mode manually have not worked, as it appears a sync is firing, which triggers DataBound, which tromps all over my row that I just put into edit mode.  

Is there a way to:
1.  Instruct a grid to keep edit mode open (with the original values) when an Error event is triggered from a DataSource save?
or
2. Define a custom client-side validation step to perform the check against those booleans before the DataSource Save?

6 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 26 Jul 2013, 11:13 AM
Hello Sarah,

Preventing the Grid from exiting edit mode is not supported out of the box but can be achieved by using the approach from this code-library. 
As for creating validation you could define a custom validation attribute (or just extend the Kendo validator)as demonstrated in the "Custom validator editing" demo in the offline examples project that is included with the installation. You could also use the Grid save event and use the event argument preventDefault method to prevent the data to be posted when there are invalid values.

Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Ezequiel
Top achievements
Rank 2
answered on 17 Apr 2014, 07:56 PM
Hi Daniel, I've downloaded this example linked on your answer to Sarah.
It worked properly on that project, when I add the same code to my project this args.sender.options.table is null. I have args, sender and options, but table is null.

I guess it's something that changed in latests versions of Kendo. Is there any other way of doing that?
I have some Business validation rules on server side that may cause some exception that I add to ModelState and I want to keep edit mode open.

Thanks,
Ezequiel
0
Alexander Popov
Telerik team
answered on 21 Apr 2014, 02:04 PM
Hello Ezequiel,

The DataSource events no longer provide a reference to the Grid through the args.sender argument. You could however, get the Grid's instance manually. For example: 
var grid = $("#Grid").data("kendoGrid");
grid.table ...
In case the event handler will be shared among multiple Grids, then you could pass the Grid's ID:
.Events(events => events.Error("error_handler.bind({WidgetID: '#Products'})"))
 
....
 
 
<script type="text/javascript">
    function error_handler(e) {
        var grid = $(this.WidgetID).data("kendoGrid");
        ....
</script>


Regards,
Alexander Popov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Ezequiel
Top achievements
Rank 2
answered on 22 Apr 2014, 10:57 AM
Today we have an unique javascript function to handle errors. We're migrating from Telerik MVC Extensions to Kendo.
So, for a basic and logical thing, our team will need to copy a function to every grid we have on our system?
I don't see any logic in not keeping in Edit Mode by default when the ModelState is invalid...
0
Daniel
Telerik team
answered on 24 Apr 2014, 01:09 PM
Hello Ezequiel,

I am afraid that adding this functionality as built-in one is not currently planned. If you believe that this should be the default behavior then I can suggest to open a feature request in our user voice forum.

Regards,
Daniel
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Samer
Top achievements
Rank 1
answered on 21 Jul 2014, 01:35 PM
Man.. you saved my day with this post... THANKS!!!
Tags
Grid
Asked by
Beth
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Ezequiel
Top achievements
Rank 2
Alexander Popov
Telerik team
Samer
Top achievements
Rank 1
Share this question
or