Generic Filters Component
The GenericFiltersComponent is designed to dynamically generate and manage filter fields based on a provided schema. It integrates with Angular's reactive forms to retrieve and reset filter values while supporting additional utilities like date handling and input type customization.
How to use the component in your app :
import the component :
import {GenericFiltersComponent} from '@tradinos/cms-frontend-entity';The selector for component , like it :
<lib-cms-generic-filters></lib-cms-generic-filters>2. Define the filterSchema
The filterSchema defines the structure and behavior of the filters:
example
Features
Dynamic Filters:
Automatically generates filter fields based on the
FilterSchemaconfiguration.
Filter Retrieval:
Provides a method (
getFilters) to retrieve the current filter values as an object.
Reset Filters:
Resets all filters to their default or empty values with the
resetFiltersmethod.
Date Handling:
Includes utilities to handle date ranges and convert dates to ISO format for consistent querying.
Customizable Input Types:
Supports various input types defined in
FilterInputTypefor flexibility in filter field design.
Content Projection:
Allows custom templates for titles and actions using Angular content projection.
Inputs
filterSchema(optional)
A schema object defining the filter fields, their types, and configurations.
Example:
Methods
1. ngOnInit(): void
Description:
Lifecycle hook called when the component initializes.
Subscribes to value changes in the filter fields for real-time updates.
Behavior:
Triggers change detection to ensure the UI is updated correctly.
2. getFilters(): { [key: string]: any }
Description:
Retrieves the current filter values as a key-value pair object.
Applies transformations such as cleaning empty values and formatting dates.
Return Value:
An object where keys represent filter field names and values represent the user's input.
3. resetFilters(): void
Description:
Resets all filter fields to their default or empty values.
4. Private Methods
clean(filters: { [key: string]: any }): { [key: string]: any }Removes empty or null values from the filter object.
Ensures only meaningful filter criteria are submitted.
convertDateToIsoDate(date: Date): stringConverts a
Dateobject to an ISO date string for consistent querying.Used internally for date-based filters.
subscribeValueChanges()Monitors changes to filter fields for real-time updates.
Last updated