We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Grid - Custom Validation

Hello,

I'm trying to add a Custom Validation to a column, but I got a syntax error. I was following your documentation example:



We're using Syncfusion 16.4.0.44. In addition, this link is broken: https://ej2.syncfusion.com/16.1.24/aspnet/documentation/form-validator.html#defining-custom-rules

Thanks in advance.

1 Reply

TS Thavasianand Sankaranarayanan Syncfusion Team January 8, 2019 05:56 AM UTC

Hi Matias, 

Greetings from Syncfusion. 

Sorry for the inconvenience caused. 

Query #1: I'm trying to add a Custom Validation to a column, but I got a syntax error. I was following your documentation example: 

Currently, Grid do not have the tag helper support for custom validation rules. So we suggest you to use Grid Load event to achieve this requirement like as follows, 

@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.data).AllowPaging(true).Load("load").Columns(col => 
{ 
 
    col.Field("OrderID").HeaderText("OrderID").IsPrimaryKey(true).Width("120").Add(); 
    col.Field("CustomerID").HeaderText("CustomerID").Width("120").Add(); 
    col.Field("EmployeeID").HeaderText("EmployeeID").Width("120").Add(); 
    col.Field("ShipCity").HeaderText("ShipCity").Width("120").Add(); 
 
}).EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Normal); }).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render() 
 
<script type="text/javascript"> 
    function load(args) { 
        this.columns[1].validationRules = { required: true, minLength: [customFn, 'Need atleast 5 letters'] }; 
    } 
 
    function customFn(args) { 
        return args['value'].length >= 5; 
    } 
</script> 
 
Also we could see that we have used razor and tag helper to provide custom validation in our mvc and core help documentation code. We have already logged documentation task to change this code in the documentation. The changes will be available in any of our upcoming release. 

Refer the below link to know about Grid Load event, 



We suggest you to use below documentation and demo link to know about our form-validator instead of that link, 



Regards, 
Thavasianand S. 


Loader.
Live Chat Icon For mobile
Up arrow icon