Hello,
i am using NetAdvantage 2012.1 and would like to know if grid editor are supporting DataAnnotation validation.
Thank you
Hardis
Hi Hardis,Yes, any igEditor that you use in the igGrid's Updating feature can have data annotation validation.It's currently not described in the documentation and in the igEditors data annotation validation sample, but here's a breakdown of the logic that you need to be aware of:1. The data annotation validation is handled by the igValidator's errorLabel option - you can see more details on it here: https://www.igniteui.com/help/api/2019.1/ui.igvalidator#options:errorMessage 2. Each igEditor you use can have its own set ot validation options configured via the validatorOptions option (more info at https://www.igniteui.com/help/igvalidator-migration-topic#options_changes) 3. When using the igGrid's Updating feature, you can use the columnSettings option (https://www.igniteui.com/help/iggrid-columnmoving-propertyreference#columnSettings) to tweak the igEditor used for a specific column. The editorOptions options is the one to take note of.When we put the knowledge for all of these together, you're almost ready with the data annotation validation. The final piece of the puzzle is to have a SPAN, LABEL or DIV element on your page that has the data-valmsg-for attribute that corresponds to the errorLabel you've set for the igValidator, used for the validation of an igEditor used by the igGrid Updating feature. For example:[code]<span class="field-validation-valid" data-valmsg-for="ProductIDValidationError" data-valmsg-replace="true"></span>[/code]
I know it may sound difficult, but it's not :). To make sure I'm not lying to you, I've attached a simple HTML page to my reply where you can see the data annotation validation in action.Currently only the ProductID column is configured to have it, but I think that's enough to illustrate the concept.
Let us know if you have any trouble or further questions.Cheers!Borislav
hi,
Can you explain more specific how to integrate custom validation with specific column in iggrid? how to setup the editorOptions option? I am trying to do a server-side validation when user add/edit row in grid.
it will be great if you could provide some sample code.
thanks,
Yi
Hi Yi,I'll need to start my answer by re-ordering the sentences of your request in order to provide a proper answer and relation to the previous posts in this thread.
Yi Lin said: I am trying to do a server-side validation when user add/edit row in grid.
OK, although the original poster asked for assistance in configuring the MVC igGrid, my ultimate goal was to help them configure the client-side validation message (thus it although MVC DataAnnotations were used, they weren't taken into consideration in my HTML sample from the previous post).
Yi Lin said: how to setup the editorOptions option?
From what I managed to read and implement so far, the editorOptions option won't be of any use to us in this scenario :(. This is due to the fact that MVC DataAnnotations are meant for HTML forms with server-side defined fields for 1 object - having a different scenario (such as editors of a new/existing row in any sort of grid view), requires a custom (and damn tricky) implementation which ,as far as I was able to understand, cannot be handled by simply using the editorOptions.The reason for this is that when you POST the grid transaction over to the server, the MVC data annotation mechanism cannot kick in - you are not posting a form to which the ASP.NET MVC JavaScripts can hook to and simply display the validation error(s).
Yi Lin said:Can you explain more specific how to integrate custom validation with specific column in iggrid?
Assuming DataAnnotation attributes are indeed used for one or more of the fields of the class which represents 1 row of data in the igGrid, we can still use the MVC DataAnnotations server-side validation logic. Thus, my implementation has the following logic:
Disclaimer: There might be a better way to solve your predicament, but this solution I'm providing is the only one I could piece together.Additional reference (if you're interested):
Yi Lin said:it will be great if you could provide some sample code.
Whenever possible I do try giving a running solution. However, when it comes to something this complicated, you will most often end up with just an advice because providing a working sample means investigating and checking everything stated which can take up a lot of time. Believe it or not, it took me 4 hours to conduct the investigation and to get the sample running properly for this forum thread.Thus, be thankful with what you can get ;).PS: By the way, I believe that the answer to your question is much more suited for a post in our blogs. Since I don't have the permissions to post there, I'll ask my colleagues from the evangelism team if they can spare some time to cook up a post about the predicament and the solution.Cheers,Borislav
Hi,
you are right, I am doing server-side validations. Thanks for your reply, helps me better understand iggrid and igEditors' validation.
Hi Yi,Yeah, now that I read your question, I should have distinguished that your case doesn't concern MVC DataAnnotation validation :(
Yi Lin said: solved this problem with ajaxComplete and placed a validation summery in front of the grid, though this is not really desirable(ideal solution will be having customized validation rules in ColumnSettings, like required: true, ), it did solve my predicament. thanks!
hi Borislav,
thansk very much for your reply. Sorry that I misunderstood the original question in this post, coz I am not doing MVC DataAnnotation validation,and I just searched your previous reply and found the following...so i thought editorOptions would help me...
3. When using the igGrid's Updating feature, you can use the columnSettings option (http://help.infragistics.com/jQuery/2012.1/ui.iggridupdating#options) to tweak the igEditor used for a specific column. The editorOptions options is the one to take note of.
anyway, your answer is very helpful...I solved this problem with ajaxComplete and placed a validation summery in front of the grid, though this is not really desirable(ideal solution will be having customized validation rules in ColumnSettings, like required: true, ), it did solve my predicament. thanks!