Search K
Appearance
With a NumberField<TValue>
you can represent numerical values from an entity. This is useful for contexts where quantitative data is involved.
A NumberField<TValue>
has one generic type parameter.
The TValue
denotes the underlying numeric type and must implement the INumber
interface. Most built-in value types, such as int
, double
or float
implement INumber
.
In our demo application we use an int
property to store an employee's weekly hours.
public class Employee
{
[Key]
public int Id { get; init; }
public int WeeklyHours { get; set; }
}
You can add it to a resource by adding it to the list of available fields. As the numeric value is of type int
, the NumberField
will be typed as such.
public override IList<IResourceFieldBuilder> Fields()
{
return
[
NumberField<int>.Make("Weekly Hours", nameof(Employee.WeeklyHours)),
];
}
A NumberField
displays its underlying numeric value.
In Create and Update views a user will see a numeric input field.
The default visibility values are as follows:
Resource View | Default |
---|---|
Index | visible |
Create | visible |
Update | visible |
Details | visible |
You can change the visibility of the field for each view. Please note, however, that fields should remain visible on Create pages if the field is required by the entity model and if no default value is set.
A NumberField
can be made sortable by chaining a call to Sortable()
after adding the field. Sorting will be performed in numeric order.
public override IList<IResourceFieldBuilder> Fields()
{
return
[
NumberField<int>.Make("Weekly Hours", nameof(Employee.WeeklyHours))
.Sortable(),
];
}
We provide a default filter for number fields. Simply chain a Filterable()
method call after the field definition. The filter will allow users to filter by minimum and maximum values.
public override IList<IResourceFieldBuilder> Fields()
{
return
[
NumberField<int>.Make("Weekly Hours", nameof(Employee.WeeklyHours))
.Filterable(),
];
}