-
Notifications
You must be signed in to change notification settings - Fork 0
Select filter
The AbstractSelectFilter class is an abstract base class for implementing a select filter that operates with predefined options such as single or multi-select. This filter allows the user to select from options and applies equality or inclusion operations to filter data.
The class is generic and uses three type parameters:
-
T: The data type that the options operate on (e.g.,string,number). -
R: The type of operations that the filter supports, either:EqualOperation.EqualInOperation
-
V: The type of option used by the filter, which can either be:SelectOptionMultiSelectOption
constructor(column: string, label: string, options: V[], conditions?: Condition[])-
column: string: The name of the column or field that the filter applies to. -
label: string: The label or display name for the filter. -
options: V[]: The list of selectable options in the filter. -
conditions?: Condition[]: An optional array of initial conditions for the filter.
protected _options: V[];-
Type:
V[] - Description: A protected array of selectable options in this filter.
get options(): V[];-
Type:
V[] - Description: Getter method that retrieves the available options for the filter.
- Returns: An array of options that can be selected in the filter.
abstract selectOption(value: T): void;-
Type:
void - Description: Abstract method for selecting an option within the filter. Subclasses must implement this method to define how an option is selected.
-
Parameters:
-
value: T: The value to be selected from the options.
-
apply(): void;-
Type:
void -
Description: Applies the filter and emits the filter's
onApplyevent. This method signals that the filter has been applied. - Remarks: It should be called after selecting or modifying options, but it does not modify any conditions.
The AbstractSelectFilter class provides a foundation for creating select-based filters where the user can choose from predefined options. Subclasses of this class must implement the selectOption method to handle option selection logic.
Assume you want to create a select filter for filtering a dataset based on a list of user roles. You could create a subclass of the AbstractSelectFilter class to implement this functionality (see here).
class RoleSelectFilter extends AbstractSelectFilter<
T,
EqualOperation.Equal,
SelectOption<T>
> {
public selectOption(value: string): void {
// Custom selection logic
}
}Once created, the RoleSelectFilter can be instantiated and used as follows:
const roleOptions = [
new SelectOption("Admin", "admin"),
new SelectOption("User", "user"),
new SelectOption("Guest", "guest"),
];
const roleFilter = new RoleSelectFilter("role", "User Role", roleOptions);
roleFilter.selectOption("Admin");
roleFilter.apply(); // Triggers the onApply event