Is there an easy way to the the max value of a grid cell to a row property value

I would like to have to inline numeric editor to test the maximum value. 
But it is set per row to the rows MaxQuantity value.
How can this be done?
I was thinking of something like this, but context is not known:

<Syncfusion.Blazor.Grids.GridColumn Field=@nameof(LineItem.Quantity) HeaderText="Qty" EditType="EditType.NumericEdit" EditorSettings="@QuantityEditParams" ValidationRules="@(new ValidationRules{ Required= true, Max = @((context as LineItem).MaxQuantity) })"  Width="80px" />

2 Replies 1 reply marked as answer

RN Rahul Narayanasamy Syncfusion Team March 10, 2021 01:17 PM UTC

Hi Iwan, 

Greetings from Syncfusion. 

Query: Is there an easy way to the the max value of a grid cell to a row property value 

We have validated your query and you want to set one of the row value  as maximum value to numeric column validation.  You can achieve your requirement by using CustomValidation.  Find the below code snippets and sample for your reference. 

 
<SfGrid DataSource="@Orders" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })" 
        AllowSelection="true" AllowFiltering="true"> 
    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true"></GridEditSettings> 
    <GridColumns> 
        . . . 
        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" ValidationRules="@(new ValidationRules{ Required= true })" TextAlign="TextAlign.Right" Width="120"> 
 
        </GridColumn> 
    </GridColumns> 
</SfGrid> 
 
@code{ 
    public List<Order> Orders { get; set; } 
 
    . ..  
 
    public class Order 
    { 
        public int? OrderID { get; set; } 
        public string CustomerID { get; set; } 
        public DateTime? OrderDate { get; set; } 
        [CustomValidation] 
        public double? Freight { get; set; } 
        public int? MaxQuantity { get; set; } 
    } 
 
    [AttributeUsage(AttributeTargets.Property)] 
    public class CustomValidationAttribute : ValidationAttribute 
    { 
        protected override ValidationResult IsValid(object value, ValidationContext validationContext) 
        { 
            var Res = false; 
            if((double?)value != null) 
            { 
                if ((double)value > (validationContext.ObjectInstance as Order).MaxQuantity) 
                { 
                    Res = true; 
                } 
            } 
            return Res ? new ValidationResult("Freight Value must be smaller", new[] { validationContext.MemberName }) : ValidationResult.Success;   //if the entered value in Freight column exceeds the MaxQuantity value of the record, then the validation error will be shown 
        } 
    } 
 
} 



Please let us know if you have any concerns. 

Regards, 
Rahul 



RN Rahul Narayanasamy Syncfusion Team March 10, 2021 01:21 PM UTC

Hi Iwan, 

Greetings from Syncfusion. 

Query: Is there an easy way to the the max value of a grid cell to a row property value 

We have validated your query and you want to set one of the row value  as maximum value to numeric column validation.  You can achieve your requirement by using CustomValidation.  Find the below code snippets and sample for your reference. 

 
<SfGrid DataSource="@Orders" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })" 
        AllowSelection="true" AllowFiltering="true"> 
    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true"></GridEditSettings> 
    <GridColumns> 
        . . . 
        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" ValidationRules="@(new ValidationRules{ Required= true })" TextAlign="TextAlign.Right" Width="120"> 
 
        </GridColumn> 
    </GridColumns> 
</SfGrid> 
 
@code{ 
    public List<Order> Orders { get; set; } 
 
    . ..  
 
    public class Order 
    { 
        public int? OrderID { get; set; } 
        public string CustomerID { get; set; } 
        public DateTime? OrderDate { get; set; } 
        [CustomValidation] 
        public double? Freight { get; set; } 
        public int? MaxQuantity { get; set; } 
    } 
 
    [AttributeUsage(AttributeTargets.Property)] 
    public class CustomValidationAttribute : ValidationAttribute 
    { 
        protected override ValidationResult IsValid(object value, ValidationContext validationContext) 
        { 
            var Res = false; 
            if((double?)value != null) 
            { 
                if ((double)value > (validationContext.ObjectInstance as Order).MaxQuantity) 
                { 
                    Res = true; 
                } 
            } 
            return Res ? new ValidationResult("Freight Value must be smaller", new[] { validationContext.MemberName }) : ValidationResult.Success;   //if the entered value in Freight column exceeds the MaxQuantity value of the record, then the validation error will be shown 
        } 
    } 
 
} 



Please let us know if you have any concerns. 

Regards, 
Rahul 


Marked as answer
Loader.
Up arrow icon