pg-filters
v1.1.0
Published
Easily filter any list of data with ready to use functions.
Readme
pg-filters
Functions
searchData
Filters data by using a single search string and matching its value with all the filters. Only uses Textand Number filters.
| Parameter | Type | Usage
| ------------- | ------------- | ------------- |
| data | any[] | List of objects that need to be filtered.
| filters | Filter[] | List of filters that will be used to filter data.
| search | string | What the user entered in the search box.
filterData
Filters data by using the filters.
| Parameter | Type | Usage
| ------------- | ------------- | ------------- |
| data | any[] | List of objects that need to be filtered.
| filters | Filter[] | List of filters that will be used to filter data.
getActiveFilters
Returns all the filters that have a value.
| Parameter | Type | Usage
| ------------- | ------------- | ------------- |
| filters | Filter[] | Filters to be evaluated.
resetFilters
Resets the value of the filters to their original state.
| Parameter | Type | Usage
| ------------- | ------------- | ------------- |
| filters | Filter[] | Filters to be reset.
restoreFiltersFromStorage
Restores filters from a JSON storage, converting each field to its original state.
| Parameter | Type | Usage
| ------------- | ------------- | ------------- |
| storage | string | JSON storage.
Filter Object
| Field | Usage | Required
| ------------- | ------------- | ------------- |
| field | Must match the field name inside the filtered object. | ✓
| label | Used to show the filter's name to the user. |
| inputType | Specifies the type of input that the user will interact with. Available types are Text, Number, Dropdown, MultiSelect, Calendar, CalendarRange and Checkbox | ✓
| filterType | Specifies the method that will be used to filter. |
| value | Used to compare values with the filtered object. User input goes there. |
| options | Used to populate a filter with options. Should only be used with Dropdown and MultiSelect. |
| empty | Sets the empty value to be matched with when filtering using Dropdown and MultiSelect. |
| category | Used to group fields together in a form. |
Filter Types
| Input Type | Associated Filter Types | Default
| ------------- | ------------- | ------------- |
| Number, Calendar | Less, LessOrEqual, Equal, GreaterOrEqual, Greater. | Equal
| Checkbox | True, False. | True
