Hi All,
I have implemented the data grid custom-validation example supplied by Syncfusion in the examples, every thing is ok except it dos not display the error message for the columns validations.
I am using Version="20.4.0.43".
Any solution please.
Thank you very much.
Hi Tarik,
Greeting from Syncfusion support.
If you are facing an issue with custom validation not displaying the error message in a Syncfusion Blazor grid, you can try the following steps to resolve it:
1.Make sure the error message is being set properly in the custom validation logic.
2.Ensure that the grid's EditForm component is properly configured to display error messages.
3.Check if the DataAnnotations attributes are applied correctly on the model property to validate.
4.If the issue persists, you can refer to the UG documentation for more information.
https://blazor.syncfusion.com/documentation/datagrid/column-validation
If you still face this issue, Kindly share us the following things:
1.The entire Grid code snippet.
2.Share more details about your requirement elaborately
3.Share us the video demonstration of the issue with replication procedure.
4.If possible kindly share us the issue reproduceable sample.
The above-requested details will be very helpful for us to validate the reported query at our end and provide the solution as early as possible.
Regards,
Bala
Thank you very much for your response.
About this 2.Ensure that the grid's EditForm component is properly configured to display error messages.
I am not using edit form i am using grid with edit normal and following is the grid as it was in the example :
@page "/datagrid/custom-validation"
@using Syncfusion.Blazor.Grids;
@using System.ComponentModel.DataAnnotations;
@using System.Text.RegularExpressions;
<SfGrid DataSource="EmployeeList" AllowPaging="true" Toolbar="toolbar">
<GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true"></GridEditSettings>
<GridColumns>
<GridColumn Field="@nameof(EmployeeDetails.OrderID)" HeaderText="Order ID" TextAlign="TextAlign.Right" IsPrimaryKey="true" > </GridColumn>
<GridColumn Field="@nameof(EmployeeDetails.CustomerName)" HeaderText="Customer Name" TextAlign="TextAlign.Left"> </GridColumn>
<GridColumn Field="@nameof(EmployeeDetails.EmployeeID)" HeaderText="Employee ID" TextAlign="TextAlign.Right"> </GridColumn>
<GridColumn Field="@nameof(EmployeeDetails.Freight)" HeaderText="Freight" TextAlign="TextAlign.Right" Format="C2"> </GridColumn>
<GridColumn Field="@nameof(EmployeeDetails.ShipCity)" HeaderText="Ship City" TextAlign="TextAlign.Left"> </GridColumn>
<GridColumn Field="@nameof(EmployeeDetails.ShipName)" HeaderText="Ship Name" TextAlign="TextAlign.Left"> </GridColumn>
</GridColumns>
</SfGrid>
@code
{
List<EmployeeDetails> EmployeeList;
string[] toolbar = new string[] { "Add", "Edit", "Delete", "Update", "Cancel" };
protected override void OnInitialized()
{
base.OnInitialized();
EmployeeList = Enumerable.Range(1, 20).Select(x => new EmployeeDetails()
{
OrderID = 10240 + x,
CustomerName = new string[] { "VINET", "TOSMP", "HANAR", "VICTE" }[new Random().Next(4)],
EmployeeID = x,
Freight = new float[] { 32.28f, 22.90f, 30.99f, 50.52f }[new Random().Next(4)],
ShipCity = new string[] { "Reims", "Munster", "Rio de Janeir", "Lyon" }[new Random().Next(4)],
ShipName = new string[] { "Vins et alocools chevalie", "Toms Spezialitaten", "Hanari Carnes", "Supremes delices" }[new Random().Next(4)]
}).ToList();
}
public class EmployeeDetails
{
[Required]
public int? OrderID { get; set; }
public string CustomerName { get; set; }
[CustomValidationEmployeeID]
public int EmployeeID { get; set; }
[CustomValidationFreight]
public float Freight { get; set; }
public string ShipCity { get; set; }
public string ShipName { get; set; }
}
public class CustomValidationEmployeeID : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if (value != null)
{
int employeeID = Convert.ToInt16(value);
if (employeeID >= 1)
{
return ValidationResult.Success;
}
else
{
return new ValidationResult("Employee ID value should be greater than zero");
}
}
else
{
return new ValidationResult("Employee ID value is required");
}
}
}
public class CustomValidationFreight : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if (value != null)
{
float freight = (float)value;
if (freight >= 1 && freight <= 10000)
{
return ValidationResult.Success;
}
else
{
return new ValidationResult("Freight value should between 1 and 10,000");
}
}
else
{
return new ValidationResult("Freight value is required");
}
}
}
}
Dear Tarik,
Thank you for reaching out to us regarding your issue. I understand that it can be frustrating to experience any challenges while using our product.
We would like to offer a solution that may help resolve your issue. Our latest version of the software has been designed to address such concerns, and we believe that it will be beneficial for you to upgrade to this version.
For your convenience, we have also attached a solution file that contains all the necessary information. Please refer to this attachment for a detailed explanation of the solution.
If you have any further questions or concerns, please do not hesitate to reach out to us. We are always here to help.
Best regards,
Bala,
Syncfusion Support Team.
Thank you so much for your kindly answer.
I have downloaded the attached sample and it works as expected displaying the error message for each column and it is working fine.
I took the same page from the attached sample datagrid/custom-validation from the index razor page and copy it exactly in my system but it dos not work as in the example supplied (not showing the error message).
BTW: I am using web assembly Blazor with .Net 6, and installed only 2 Syncfusion packages from github :
1-Syncfusion.Blazor.Grid.
2-Syncfusion.Blazor.Themes.
And both Version="20.4.0.48", did I missed any package that I should install?.
Thank you very much for your cooperation.
Hi Tarik,
Greeting from Syncfusion support.
To properly display the error message, there are a few things you should check:
Kindly refer the attached solution file to resolve your issue.
Please get back to us if you have further queries.
Regards,
Bala.
About points from 2 to 4 are ensured because I have copied the same page from the sample you provide.
I have doubt about point 1, could you please tell me what is the package required for this because I do not want to install all the Syncfusion.Blazor package as there are most of the component provided by the full package I do nto use them and I don not want over head for them.
Thank you very much.
Hi Tarik,
Thank you for reaching out to us.
We understand that you may have concerns about installing the Syncfusion.Blazor component. To assist you further, we have created a sample using our individual component, Syncfusion.Blazor.Grids, which we believe will help address your needs.
We have attached the solution file for your reference. Please let us know if this sample meets your requirements or if you have any further questions.
We hope this resolves your concerns and look forward to hearing from you soon.
Best regards,
Bala,
Syncfusion Support Team.