1

Good day, I am new to Dev express and also to razor pages.

I have a dev extreme data grid with a list of users, a user has a user type the user type has a min range and a max range for the user id.

What I want is to set a range validation rule on a column on the standard edit form of the datagrid so when you add a new user id the user id should be between for example 1 and 49999. The range is stored in a database. So the user first selects the user type, the usertype table will have a range in it for example a user type of "Employee" will have a range of min 1 max 49999, this range I want to use as validation on my form.

My DevExtreme datagrid code currently :

@(Html.DevExtreme().DataGrid<ACS.LIB.BE.User>().ID("userGrid")
.ElementAttr(new { @class = "dx-card wide-card" })
.DataSource(d => d.Mvc().Controller("User")
    .LoadAction("Get").Key("ID")
    .InsertAction("InsertUser")
    .UpdateAction("UpdateUser")
    .DeleteAction("DeleteUser"))
.ShowBorders(false)
.FilterRow(f => f.Visible(true))
.FocusedRowEnabled(true)
.FocusedRowIndex(0)
.ColumnAutoWidth(true)
.ColumnHidingEnabled(true)
.Columns(columns =>
{
    columns.AddFor(m => m.ID).ValidationRules(val => val.AddRange().Min(100));
    columns.AddFor(m => m.Name);

    columns.AddFor(m => m.UserType.ID).Lookup(lookup => lookup
                    .DataSource(ds => ds.WebApi().Controller("UserType").LoadAction("Get").Key("ID"))
                    .DisplayExpr("Name")
                    .ValueExpr("ID")
                    ).Caption("User Type");
    columns.AddFor(m => m.Department.ID).Lookup(lookup => lookup
                    .DataSource(ds => ds.WebApi().Controller("Department").LoadAction("Get").Key("ID"))
                    .ValueExpr("ID")
                    .DisplayExpr("Name")
                    ).Caption("Department");
    columns.AddFor(m => m.Company.ID).Lookup(lookup => lookup
                    .DataSource(ds => ds.WebApi().Controller("Company").LoadAction("Get").Key("ID"))
                    .ValueExpr("ID")
                    .DisplayExpr("Name")
                    ).Caption("Company");
    columns.AddFor(m => m.Authority);
    columns.AddFor(m => m.Email).ValidationRules(v => v.AddEmail().Message("Please enter a valid email address. yourname@yourdomain.com"));
    columns.AddFor(m => m.Active).FilterValue(true);

})

The line I have a problem with is columns.AddFor(m => m.ID).ValidationRules(val => val.AddRange().Min(100));

The Min(100) I want to set it dynamically from a data source not hardcoded like it is now, the user first selects the Usertype and then I want to use the UserType table to get the range what the id should be in. So I want to fetch the 100 from my user table but I am not sure what the syntax would be or how I should go about doing it.

My usertype table : enter image description here

My insert screen default popup from the edit dialog of the data grid. enter image description here

Any help or pointers would be appreciated.

Renier
  • 1,738
  • 3
  • 24
  • 51

1 Answers1

0

It looks like you need to define a custom validation rule instead. You can get a user type value using the options.data parameter in the validationCallback function.

Note that the best ASP.NET Core practice is to use model properties' Data Annotation validation attributes. DevExtreme ASP.NET Core components support them.

You can find code snippets in the Implement a Custom Validation Rule topic.