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 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-mat-table-filter

v16.0.2

Published

MatSort like filter directive for Angular material's MatTable component

Downloads

16

Readme

ng-mat-table-filter

This library adds MatSort like column based filter functionality to Angular Material MatTable component.

How to use

Assuming your application is already up and running using Angular Material, you can add this library by following these steps:

  1. Install ng-mat-table-filter:

    npm i ng-mat-table-filter
  2. Import the MatTableFilterModule and add it to the module that declares your component:

    import {MatTableModule} from '@angular/material/table';
    import {MatTableFilterModule} from 'ng-mat-table-filter';
    
    @NgModule({
      declarations: [MyComponent],
      imports: [MatTableModule, MatTableFilterModule],
    })
    export class MyModule {}
  3. Use the directives in your component's template:

    <table mat-table matTableFilter [dataSource]="dataSource">
      <ng-container matColumnDef="position">
        <th mat-header-cell mat-table-filter-header *matHeaderCellDef>No.</th>
        <td mat-cell *matCellDef="let data">{{data.position}}</td>
      </ng-container>
    
      <ng-container matColumnDef="name">
        <th mat-header-cell mat-table-filter-header *matHeaderCellDef>Name</th>
        <td mat-cell *matCellDef="let data">{{data.name}}</td>
      </ng-container>
    
      <tr mat-header-row *matHeaderRowDef="myColumns"></tr>
      <tr mat-row *matRowDef="let row; columns: myColumns;"></tr>
    </table>

Using mat-filter-table-header with mat-sort-header

To use both mat-filter-table-header and mat-sort-header together:

<ng-container matColumnDef="position">
  <th mat-header-cell mat-table-filter-header *matHeaderCellDef>
    <div mat-sort-header>No.</div>
  </th>
  <td mat-cell *matCellDef="let data">{{data.position}}</td>
</ng-container>

Rendered template

As default MatTableFilterComponent using for filter triggerer. But you can give your custom components that extends MatTableFilterTriggerer<T> base class as well:

import {MatTableModule} from '@angular/material/table';
import {MAT_TABLE_TRIGGERER_TYPE, MatTableFilterSelection, MatTableFilterModule, MatTableFilterTriggerer} from 'ng-mat-table-filter';

@Component({
  /**/
})
class MyCustomComponent extends MatTableFilterTriggerer<MatTableFilterSelection> {}

@NgModule({
  declarations: [MyComponent],
  imports: [MatTableModule, MatTableFilterModule],
  providers: [
    {
      provide: MAT_TABLE_TRIGGERER_TYPE,
      useValue: Type<MyCustomComponent>,
    },
  ],
})
export class MyModule {}

Header type

There are 3 different types of default MatTableFilterButton. string, number and boolean. By default every filter header directive type is string. You can define the type by giving matTableFilterHeaderType input to mat-table-filter-header;

<ng-container matColumnDef="weight">
  <th mat-header-cell mat-table-filter-header matTableFilterHeaderType="number" *matHeaderCellDef>Weight</th>
  <td mat-cell *matCellDef="let element">{{ element.weight }}</td>
</ng-container>
<ng-container matColumnDef="learned">
  <th mat-header-cell mat-table-filter-header matTableFilterHeaderType="boolean" *matHeaderCellDef>Learned</th>
  <td mat-cell *matCellDef="let element">{{ element.learned ? 'Yes' : 'No' }}</td>
</ng-container>

Live stackblitz demo