a4-pivot-table
TypeScript icon, indicating that this package has built-in type declarations

9.0.0 • Public • Published

a4-pivot-table

Angular 7 Pivot Table

How-To

Install

npm install a4-pivot-table

app.module.ts

  1. Add PivotTableModule to imports.
 
...
import { PivotTableModule } from 'a4-pivot-table';
...
 
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    ...,
    PivotTableModule,
    ...
  ],
  ...
})

your.component.html

<pivot-table [data]="data"
  [x]="x" [y]="y" [renderCell]="renderCell">
</pivot-table>

example

<pivot-table [data]="[{a: 'A1', b:'B1', c:'C3', d:1}, {a: 'A1', b:'B2', c:'C3', d:2}, {a: 'A2', b:'B2', c:'C2', d:3}, {a: 'A3', b:'B2', c:'C2', d:4}]"
  [x]="['b', 'c']" [y]="['a']" [renderCell]="renderCell">
</pivot-table>

your.component.ts

interface IData {
  a: string;
  b: string;
  c: string;
  d: number;
}
 
@Component({
  ...
  ...
})
export class YourComponent {
  ...
  data: IData[] = [
    {a: 'A1', b:'B1', c:'C3', d:1},
    {a: 'A1', b:'B2', c:'C3', d:2},
    {a: 'A2', b:'B2', c:'C2', d:3},
    {a: 'A3', b:'B2', c:'C2', d:4}
    ];
  ...
  ...
  renderCell(x: IData[]): string {
    return x.reduce((r, c) => r + c['d'], 0);
  }
  ...
  ...
}

Readme

Keywords

Package Sidebar

Install

npm i a4-pivot-table

Weekly Downloads

10

Version

9.0.0

License

none

Unpacked Size

266 kB

Total Files

32

Last publish

Collaborators

  • cccheng