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
Thanks for your answer.
I have tested and there no Data Annotation of .NET framework displayed in Data Grid.
Here is the code :
index.cshtml :
<div id="result"> @(Html.Infragistics().Grid(Model).ID("grid2").Height("700px").PrimaryKey("Id").UpdateUrl("EditionUserLogin").Columns(column =>{ column.For(x => x.Id).HeaderText("Id").Width("50px"); column.For(x => x.Prenom).HeaderText(HttpContext.GetGlobalResourceObject("UserLogin", "ColonnePrenom").ToString()).Width("150px"); column.For(x => x.Nom).HeaderText(HttpContext.GetGlobalResourceObject("UserLogin", "ColonneNom").ToString()).Width("200px"); column.For(x => x.Login).HeaderText(HttpContext.GetGlobalResourceObject("UserLogin", "ColonneLogin").ToString()).Width("200px"); column.For(x => x.Mail).HeaderText(HttpContext.GetGlobalResourceObject("UserLogin", "ColonneMail").ToString()).Width("200px"); column.For(x => x.Telephone).HeaderText(HttpContext.GetGlobalResourceObject("UserLogin", "ColonneTel").ToString()).Width("150px");}).AutoCommit(true).Features(features => { features.Sorting(); features.Paging().PageSize(30); features.Updating().ColumnSettings(settings => { settings.ColumnSetting().ColumnKey("Id").EditorType(ColumnEditorType.Text).ReadOnly(true); settings.ColumnSetting().ColumnKey("Prenom").EditorType(ColumnEditorType.Text) .TextEditorOptions(options => { options.ValidatorOptions(option => { options.ValidatorOptions(validOptions => { validOptions.OnChange(true); }); }); }).EditorOptions(@"validatorOptions: {errorLabel: 'GridValidation'}"); settings.ColumnSetting().ColumnKey("Nom").EditorType(ColumnEditorType.Text) .TextEditorOptions(options => { options.ValidatorOptions(option => { options.ValidatorOptions(validOptions => validOptions.OnChange(true)); }); }).EditorOptions(@"validatorOptions: {errorLabel: 'GridValidation'}"); settings.ColumnSetting().ColumnKey("Login").EditorType(ColumnEditorType.Text) .TextEditorOptions(options => { options.ValidatorOptions(option => { options.ValidatorOptions(validOptions => validOptions.OnChange(true)); }); }).EditorOptions(@"validatorOptions: {errorLabel: 'GridValidation'}"); settings.ColumnSetting().ColumnKey("Mail").EditorType(ColumnEditorType.Text) .TextEditorOptions(options => { options.ValidatorOptions(option => { options.ValidatorOptions(validOptions => validOptions.OnChange(true)); }); }).EditorOptions(@"validatorOptions: {errorLabel: 'GridValidation'}"); settings.ColumnSetting().ColumnKey("Telephone").EditorType(ColumnEditorType.Text) .TextEditorOptions(options => { options.ValidatorOptions(option => { options.ValidatorOptions(validOptions => validOptions.OnChange(true)); }); }).EditorOptions(@"validatorOptions: {errorLabel: 'GridValidation'}"); }); features.Filtering(); features.Hiding(); features.Resizing(); features.Updating().Validation(true); }).DataSourceUrl(Url.Action("ChargerUserLogin")).DataBind().Render() ) @*@Html.Infragistics*@ </div> <div id="validationError"> <span class="field-validation-valid" data-valmsg-for="GridValidation" data-valmsg-replace="true"> </span> </div>
Here is the business object :
public class UserLogin { /// <summary> /// Gets or sets the id . /// </summary> /// <value> /// The id. /// </value> public int Id { get; set; } /// <summary> /// Gets or sets the nom. /// </summary> /// <value> /// The nom. /// </value> [Required(AllowEmptyStrings = false, ErrorMessage = "Le nom ne peut être nul.")] public string Nom { get; set; } /// <summary> /// Gets or sets the prenom. /// </summary> /// <value> /// The prenom. /// </value> [Required(AllowEmptyStrings = false, ErrorMessage = "Le prénom ne peut être nul.")] public string Prenom { get; set; } /// <summary> /// Gets or sets the login. /// </summary> /// <value> /// The login. /// </value> [Required(AllowEmptyStrings = false, ErrorMessage = "Le login ne peut être nul.")] public string Login { get; set; } /// <summary> /// Gets or sets the mail. /// </summary> /// <value> /// The mail. /// </value> [RegularBLOCKED EXPRESSION] public string Telephone { get; set; } }
Do i make something wrong ?