-
Notifications
You must be signed in to change notification settings - Fork 0
Operation filter
The AbstractOperationFilter class is an abstract class that represents a filter supporting operations such as comparison, equality, or "like" operations. This class restricts the filter to only one condition per instance, ensuring that filters remain focused on a single operation at a time.
This class is generic and uses two type parameters:
-
T: The data type that the filter operates on (e.g.,string,number,Date). -
R: The type of operation that the filter supports. This could be one of the following:ComparisonOperationEqualOperationLikeOperation
constructor(column: string, label: string, 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. -
conditions?: Condition[]: An optional array of conditions to initialize the filter with. This array must contain at most one condition.
If more than one condition is provided, the constructor throws a RangeError because this filter supports only a single condition.
apply(value: T, operation: R): void;-
Type:
void -
Description: Applies a new condition to the filter. This method sets a new condition using the provided value and operation, overwriting any existing condition, and emits the
onApplyevent. -
Parameters:
-
value: T: The value to be used for filtering. -
operation: R: The operation to apply (e.g., comparison, equality, or "like" match).
-
The AbstractOperationFilter class is designed to allow filtering based on a single condition using a variety of operations such as comparison or equality. It is especially useful in cases where only one filtering condition is necessary at a time.
Suppose you want to create a filter for selecting users based on their name using a "like" operation (see here):
class NameFilter extends AbstractOperationFilter {
// Additional custom methods can be added here
}
const nameFilter = new NameFilter("name", "Name Filter");
nameFilter.apply("John", LikeOperation.Like); // Filters for names that are similar to "John"