Skip to content

String operation filter

Job Haast edited this page Sep 20, 2024 · 2 revisions

String operation filter

Overview

The StringOperationFilter class is a concrete implementation of the AbstractOperationFilter class. It is designed to handle string-based filtering operations, such as equality or "like" operations. This class allows for filtering string data using either exact matches or pattern matching.

Class: StringOperationFilter

This class extends the generic AbstractOperationFilter class and specializes in string-based filtering.

Constructor

constructor(column: string, label: string, conditions?: Condition[])

Parameters:

  • 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.

Remarks:

Only one condition is allowed for operation filters. If more than one condition is provided, a RangeError will be thrown by the parent class constructor.

Properties

_conditions (protected)

protected _conditions: Condition[] = [];
  • Type: Condition[]
  • Description: The internal array of conditions for the filter. This filter allows only a single condition.

onApply (public)

onApply: EventEmitter;
  • Type: EventEmitter
  • Description: Emits an event when the filter is applied.

Methods

apply (public, override)

apply(value: string, operation: EqualOperation | LikeOperation): void;
  • Type: void
  • Description: Applies a string-based condition to the filter. This method sets a new condition using the provided string value and operation and overwrites any existing conditions. It also emits an event signaling that the filter has been applied.
  • Parameters:
    • value: string: The string value to compare or check for a match.
    • operation: EqualOperation | LikeOperation: The operation to be applied, either an equality operation or a "like" operation for pattern matching.

Remarks:

The apply method updates the filter's conditions with the given string value and operation, and then emits the onApply event to indicate that the filter has been applied.

Usage

The StringOperationFilter class is useful for filtering string-based fields in a dataset. It provides functionality to filter by both equality (exact match) and "like" operations (partial match).

Example Usage

Suppose you want to filter a dataset based on names that start with "John" using a "like" operation:

const nameFilter = new StringOperationFilter("name", "Name Filter");
nameFilter.apply("John", LikeOperation.StartsWith); // Filters for names that start with 'John'

Clone this wiki locally