Search K
Appearance
A BooleanField
is useful in scenarios when you want to store binary values, such as true/false, to represent a condition or state in a resource. Its underlying type is always a bool
.
In our demo application we use a boolean property IsExternal
to store if an employee is from an external company.
public class Employee
{
[Key]
public int Id { get; init; }
public bool IsExternal { get; set; }
}
We can then represent this property with a BooleanField
in the employee resource.
public override IList<IResourceFieldBuilder> Fields()
{
return
[
BooleanField.Make("Is External?", nameof(Employee.IsExternal)),
];
}
A BooleanField value is displayed with a checkmark icon.
In Create and Update views a user will see a checkbox that can be checked or unchecked, setting the underlying value to true
or false
.
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 BooleanField
can be made sortable by chaining a call to Sortable()
after adding the field. Sorting will be performed in the order false
then true
.
public override IList<IResourceFieldBuilder> Fields()
{
return
[
BooleanField.Make("Is External?",
nameof(Employee.IsExternal))
.Sortable(),
];
}
We provide a default filter for boolean fields. Simply chain a Filterable()
method call after the field definition. The filter will provide the user with true
and false
options in a dropdown menu.
public override IList<IResourceFieldBuilder> Fields()
{
return
[
BooleanField.Make("Is External?",
nameof(Employee.IsExternal))
.Filterable(),
];
}