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

@e-is/ngx-material-table

v17.2.0

Published

Angular 17 table based on @angular/cdk table structure, to allow row insertion, edition, validation and deletion.

Downloads

89

Readme

Angular material table (Angular 10+)

Forked from angular4-material-table

This project extends @angular/cdk data-table, also used in @angular/material table.

It extends @angular/cdk/collections DataSource in order to include a row structure, allowing row creation, inline row edition, deletion and validation.

Supported angular versions:

  • Angular 17 (v17.x)
  • Angular 16 (v0.16.0)
  • Angular 15 (v0.15.0)
  • Angular 14 (v0.14.0)
  • Angular 11 (v0.11.0 and v0.12.0)
  • Angular 10 (v0.10.0)
  • Angular <= 9: Please use angular4-material-table

@e-is/ngx-material-table

Installation

To install the package run:

npm install @e-is/ngx-material-table

Example

Example of using @e-is/ngx-material-table:

@e-is/ngx-material-table

Other example

Use

Initial steps

To use this table, first of all you must check how use angular @angular/cdk data-table.

Useful data and methods

Using this extension, you can set CDK data-table datasource with an instance of TableDataSource.

Using TableDataSource allows you to have some row related methods and data to implement add/edit/remove elements:

class TableElement<T> {
  id: number;
  editing: boolean;
  currentData?: T;
  originalData?: T;
  source: TableDataSource<T>;
  validator: FormGroup; // Used only in reactive forms.

  delete(): void;
  confirmEditCreate(): boolean;
  startEdit(): void;
  cancelOrDelete(): void;
  isValid(): boolean; // Used only in reactive forms.
}
class TableDataSource<T> {

  constructor(
    data: T[],
    dataType?: new () => T,
    validatorService?: ValidatorService,
    config = { prependNewElements: false, suppressErrors: false });

  datasourceSubject: Subject<T[]>;

  updateDatasource(data: T[], options = { emitEvent: true }): void;

  createNew(): void;

  getRow(id: number): AsyncTableElement<T>;
}

Angular4 material table example

Angular material table use example: Example of @e-is/ngx-material-table use

See this package in action

Optional libraries

Optional libraries used in the example:

"@angular/material": "16.2.11",
"@angular/forms": 16.2.12", // <- For inline validation
"material-design-icons": "^3.0.1"

person-list-reactive-forms.component.html

<mat-table [dataSource]="dataSource">
  <ng-container matColumnDef="name">
    <mat-header-cell *matHeaderCellDef> Name </mat-header-cell>
    <mat-cell *matCellDef="let row">
      <mat-form-field [floatLabel]="row.editing ? 'auto' : 'never'">
        <input matInput [formControl]="row.validator.controls['name']" placeholder="Name">
      </mat-form-field>
    </mat-cell>
  </ng-container>
  <ng-container matColumnDef="age">
    <mat-header-cell *matHeaderCellDef> Age </mat-header-cell>
    <mat-cell *matCellDef="let row">
      <mat-form-field [floatLabel]="row.editing ? 'auto' : 'never'">
        <input matInput [formControl]="row.validator.controls['age']" type="number" placeholder="Age">
      </mat-form-field>
    </mat-cell>
  </ng-container>
  <ng-container matColumnDef="actionsColumn">
    <mat-header-cell *matHeaderCellDef>
      <button mat-icon-button color="accent" (click)="dataSource.createNew()"><i class="fa fa-plus mat-icon"></i></button>
    </mat-header-cell>
    <mat-cell *matCellDef="let row">
      <button *ngIf="!row.editing" mat-icon-button color="primary" (click)="row.startEdit()">
        <mat-icon>edit</mat-icon>
      </button>
      <button *ngIf="row.editing" mat-icon-button color="primary" (click)="row.confirmEditCreate()">
        <mat-icon>done</mat-icon>
      </button>
      <button mat-icon-button color="primary" (click)="row.cancelOrDelete()">
        <mat-icon *ngIf="row.editing">undo</mat-icon>
        <mat-icon *ngIf="!row.editing">delete</mat-icon>
      </button>
    </mat-cell>
  </ng-container>

  <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
  <mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>

person-list-template-driven.component.html

<mat-table [dataSource]="dataSource">
  <ng-container matColumnDef="name">
    <mat-header-cell *matHeaderCellDef> Name </mat-header-cell>
    <mat-cell *matCellDef="let row">
      <mat-form-field [floatLabel]="row.editing ? 'float' : 'never'">
        <input [(ngModel)]="row.currentData.name" placeholder="Name" [disabled]="!row.editing" matInput>
      </mat-form-field>
    </mat-cell>
  </ng-container>
  <ng-container matColumnDef="age">
    <mat-header-cell *matHeaderCellDef> Age </mat-header-cell>
    <mat-cell *matCellDef="let row">
      <mat-form-field [floatLabel]="row.editing ? 'float' : 'never'">
        <input type="number" [(ngModel)]="row.currentData.age" placeholder="Age"  [disabled]="!row.editing" matInput>
      </mat-form-field>
    </mat-cell>
  </ng-container>
  <ng-container matColumnDef="actionsColumn">
    <mat-header-cell *matHeaderCellDef>
      <button mat-icon-button color="accent" (click)="dataSource.createNew()"><i class="fa fa-plus mat-icon"></i></button>
    </mat-header-cell>
    <mat-cell *matCellDef="let row">
      <button *ngIf="!row.editing" mat-icon-button color="primary" (click)="row.startEdit()">
        <mat-icon>edit</mat-icon>
      </button>
      <button *ngIf="row.editing" mat-icon-button color="primary" (click)="row.confirmEditCreate()">
        <mat-icon>done</mat-icon>
      </button>
      <button mat-icon-button color="primary" (click)="row.cancelOrDelete()">
        <mat-icon *ngIf="row.editing">undo</mat-icon>
        <mat-icon *ngIf="!row.editing">delete</mat-icon>
      </button>
    </mat-cell>
  </ng-container>

  <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
  <mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>

person-list.component.ts

@Component({
  selector: 'app-person-list',
  providers: [
    {provide: ValidatorService, useClass: PersonValidatorService }
  ],
  templateUrl: './person-list.component.html',
})
export class PersonListComponent implements OnInit {

  constructor(private personValidator: ValidatorService) { }

  displayedColumns = ['name', 'age', 'actionsColumn'];

  @Input() personList;
  @Output() personListChange = new EventEmitter<Person[]>();

  dataSource: TableDataSource<Person>;


  ngOnInit() {
    this.dataSource = new TableDataSource<any>(this.personList, Person, this.personValidator);

    this.dataSource.datasourceSubject.subscribe(personList => this.personListChange.emit(personList));
  }
}

class Person {
  name: string;
  age: number;
}

@Injectable()
class PersonValidatorService implements ValidatorService {
  getRowValidator(): FormGroup {
    return new FormGroup({
      'name': new FormControl(null, Validators.required),
      'age': new FormControl(),
      });
  }
}

Contributions

Any suggestion or contribution will be appreciated.

Change log

See Change log