Search K
Appearance
A DateOnlyField
is useful when you need to store or work with only a date without any reference to time. It's typically used in scenarios where the time of day is irrelevant or unnecessary, such as birthdays, deadlines or event dates. The underlying type of the field is DateOnly
.
In our demo application we use a DateOnly
property DayOfBirth
to store an employee's birthday.
public class Employee
{
[Key]
public int Id { get; init; }
[Required]
public DateOnly DateOfBirth { get; set; }
}
We use a DateOnlyField
to represent this property in our employee resource.
public override IList<IResourceFieldBuilder> Fields()
{
return
[
DateOnlyField.Make("Date of Birth", nameof(Employee.DateOfBirth)),
];
}
A DateOnlyField
displays its value formatted according to the browser's language setting (here it's the UK's date format).
In Create and Update views, a user will see a date 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 DateOnlyField
can be made sortable by chaining a call to Sortable()
after adding the field. Sorting will be performed chronologically.
public override IList<IResourceFieldBuilder> Fields()
{
return
[
DateOnlyField.Make("Date of Birth", nameof(Employee.DateOfBirth))
.Sortable(),
];
}
We provide a default filter for date fields. Chain a Filterable()
method call after the field definition. The filter will allow users to filter by a starting date and an end date.
public override IList<IResourceFieldBuilder> Fields()
{
return
[
DateOnlyField.Make("Date of Birth", nameof(Employee.DateOfBirth))
.Filterable(),
];
}