@Html.EJS().Grid("Validation").DataSource((IEnumerable<object>)ViewBag.DataSource).Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("120").ValidationRules(new { required = "true"}).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("ShipCountry").HeaderText("Ship Country").EditType("dropdownedit").Width("150").Add();
col.Field("EmployeeID").Type("s").HeaderText("EmployeeID").Width("150").Add();
col.Field("Freight").HeaderText("Freight").Width("150").Add();
}). ActionBegin("ActionBegin").AllowPaging().PageSettings(page => page.PageCount(2)).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>
function ActionBegin(args) {
if(args.requestType == 'beginEdit'){
var gridobj = document.getElementsByClassName('e-grid')[0].ej2_instances[0];
if (args.rowData["ShipCountry"] == "Germany") {
gridobj.getColumnByField("EmployeeID").validationRules = { required: true, minLength: [customFn1, 'Enter alphanumeric values'] };
}
else {
gridobj.getColumnByField("EmployeeID").validationRules = { required: true, minLength: [customFn2, 'Enter decimal value'] };
}
}
}
function customFn1(args) {
val = parseFloat(args['value']);
return (args['value'].match(/^[A-Z0-9]+$/)); // bind the condition as you want
}
function customFn2(args) {
val = parseFloat(args['value']);
return (args['value'].match(/^[0-9_.]+$/)) && (val - Math.floor(val)) != 0; // bind the condition as you want
};
</script>
|