npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@asp-devteam/filter-box

v9.0.9

Published

This package provides a simple way to add filters to an Angular application, abstracting from all the logic. Additionally, it allows the definition of complex event based behaviours, triggered by changes in the filters value or state.

Readme

Filter Box Library

This package provides a simple way to add filters to an Angular application, abstracting from all the logic. Additionally, it allows the definition of complex event based behaviours, triggered by changes in the filters value or state.

Filter Box is an Angular package developed by ALTER SOLUTIONS PORTUGAL. It has been developed using Angular 9.0.

Table of Contents

Getting started

Run npm install @asp-devteam/filter-box to install the package in your project.

Be aware that this package requires some peer dependencies to be installed:

  • "@angular/common"
  • "@angular/cdk"
  • "@angular/core"
  • "@angular/material"
  • "@angular/flex-layout" project

Usage

Next import the FilterBoxModule into your application.

import { FilterBoxModule } from '@asp-devteam/filter-box';

@NgModule({
  declarations: [AppComponent],
  imports: [FilterBoxModule.forRoot()],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {}

If you intend to use the FilterBox in multiple places accross your app, its recommended that you create a separate NgModule that imports and then exports all of your shared modules.

import { FilterBoxModule } from '@asp-devteam/filter-box';

@NgModule({
  declarations: [],
  imports: [FilterBoxModule.forRoot()],
  exports: [FilterBoxModule]
})
export class SharedModule {}

Configuration

The default FilterBox configuration, with the type FilterBoxConfig, is set at projects/filter-box-library/src/configs/configuration.ts

Customize at app-level

Copy the default FilterBox configuration to your app, and modify as needed. Then, add it the FilterBoxModule, like so

import { filterBoxConfiguration } from '../configs/filter-box.configuration';

@NgModule({
  declarations: [],
  imports: [FilterBoxModule.forRoot(filterBoxConfiguration)],
  exports: [FilterBoxModule]
})

Customize at component-level

You can also customize the config at a component-level, using input data binding.

Set your configuration first

public filterConfig: FilterBoxConfig = {
  buttons: {
    clearAll: 'full',
  },
};

And bind it to the FilterBox component

<asp-filter-box ... [filterConfig]="filterConfig"></asp-filter-box>

Basic filters

This filters provided by this package are:

To set up a FilterBox, start by instanciating the filters you want to use.

import { AutocompleteFilter, CheckboxFilter, FilterArray } from '@asp-devteam/filter-box';

filters: FilterArray = new FilterArray();

this.filters.push(
  new AutocompleteFilter('base', 'base', 'Base', () => this.pizzaService.getPizzaBases(), null),
  new CheckboxFilter('rating_medium', 'rating', 'HIGH', { id: 2, value: 'HIGH' }, false, 'RATING')

Next, insert the FilterBoxComponent selector in your template.

<asp-filter-box [filters]="filters"></asp-filter-box>

Create a getter for the filter parameters (which will be used as query parameters in an HTTP request), and listen for changes in your filters values.

import { FilterParam } from '@asp-devteam/filter-box';

get queryParams(): FilterParam[] {
  return this.filters.map(filter => filter.param).filter(filter => filter.value !== null);
}

public index(): void {
  this.someService
    .getList(this.queryParams)
    .subscribe(response => {
      // Do something
    });
}

And add it to your template.

<asp-filter-box [filters]="filters" (index)="index()"></asp-filter-box>

Make sure that the FilterBox template is only shown after the filters data has been loaded and the behaviours set

Defining filter behaviours

Out of the box, the filters will emit for the default events FilterValidValueChangeEvent and FilterClearEvent, so, if you just want to get the filter parameters to apply directly to your main list, you don't need to define specific filter behaviours.

On the other hand, if you need to capture different events, or capture events on one filter to affect another, you can do so by creating a FilterBehaviour array like this:

import { FilterBehaviour, FilterValidValueChangeEvent } from '@asp-devteam/filter-box';

filterBehaviours: FilterBehaviour[];

this.filterBehaviours = [
  {
    emitters: [this.filters.get('filterParamName')],
    events: [new FilterValidValueChangeE} from '@asp-devteam/filter-box';vent()],
    callbacks: [() => this.filters.get('filter2ParamName').disableFilter()]
  }
];

And adding the behaviours array to the template:

<asp-filter-box [filters]="filters" [filterBehaviours]="filterBehaviours" (index)="index(true)"></asp-filter-box>

A callback must always return a FilterEvent. If your callback is a custom defined function, just return a FilterEmptyEvent.

The available events are

FilterClearEvent, FilterDisabledEvent, FilterEmptyEvent, FilterEnabledEvent, FilterValidValueChangeEvent;

Note that you can use the FilterArray class instead of a Filter[], gaining access to the method get(paramName). This helps making your code more legible and less error prone.

For more information on behaviours, see the advanced filter behaviours guide.

Custom filters

Available here

Filter Array

The Filter Array class not only provides the Array API but also some additional helper methods. These are: -filterParams -> Returns the filter values as filter params (with grouped values); -toQueryParam() -> Returns the queryParams, built from the filter params; -get(name) -> Returns the filter which name matches the given name;

Additionaly, to avoid collisions, the filter array will throw an error if there are two filters with the same name.

Project Content

To project content inside the filter box, we provided to selectors. beforeFilters Will project your content before the filters & afterFilters will project your content after the filters.

<asp-filter-box [filters]="filters">
  <ng-container beforeFilters>
    My before filters custom content
  </ng-container>

  <ng-container afterFilters>
    My after filters custom content
  </ng-container>
  <asp-filter-box> </asp-filter-box
></asp-filter-box>

i18n

Unfortunetly, until https://github.com/angular/angular/issues/29536 and https://github.com/ng-packagr/ng-packagr/issues/695 are solved, i think the only viable solution is to rewrite the filters components with project specific i8n.


Copyright 2019 Alter Solutions Portugal