Angular Pivot Table

An advanced Angular pivot table component specifically engineered for complex data visualization and real-time multi-dimensional analysis. It integrates into your project in minutes, handles massive data with high speed, and offers Excel‑like features for professional analytics.


    import { Component, OnInit } from "@angular/core";
    
    @Component({
      selector: "pivotComponent",
      templateUrl: "./pivot.component.html",
      styleUrls: ["./pivot.component.css"],
    })
    export class PivotComponent implements OnInit {
      public report: Object = {
        dataSource: {
          type: "json",
          filename: "https://cdn.flexmonster.com/data/retail-data-2024.json",
          mapping: {
            "Quantity": {
              type: "number",
            },
            "Price": {
              type: "number",
            },
            "Retail Category": {
              type: "string",
            },
            "Sales": {
              type: "number",
            },
            "Order Date": {
              type: "year/quarter/month/day",
            },
            "Date": {
              type: "date",
            },
            "Status": {
              type: "string",
            },
            "Product Code": {
              type: "string",
            },
            "Phone": {
              type: "string",
            },
            "Country": {
              type: "string",
              folder: "Location",
            },
            "City": {
              type: "string",
              folder: "Location",
            },
            "CurrencyID": {
              type: "property",
              hierarchy: "Country",
            },
            "Contact Last Name": {
              type: "string",
            },
            "Contact First Name": {
              type: "string",
            },
            "Deal Size": {
              type: "string",
            },
          },
        },
        slice: {
          rows: [
            {
              uniqueName: "Country",
              filter: {
                members: [
                  "country.[australia]",
                  "country.[usa]",
                  "country.[japan]",
                ],
              },
            },
            {
              uniqueName: "Status",
            },
          ],
          columns: [
            {
              uniqueName: "Order Date",
            },
            {
              uniqueName: "[Measures]",
            },
          ],
          measures: [
            {
              uniqueName: "Price",
              aggregation: "sum",
              format: "currency",
            },
          ],
          sorting: {
            column: {
              type: "desc",
              tuple: [],
              measure: {
                uniqueName: "Price",
                aggregation: "sum",
              },
            },
          },
          expands: {
            rows: [
              {
                tuple: ["country.[japan]"],
              },
            ],
          },
          drills: {
            columns: [
              {
                tuple: ["order date.[2024]"],
              },
            ],
          },
          flatSort: [
            {
              uniqueName: "Price",
              sort: "desc",
            },
          ],
        },
        conditions: [
          {
            formula: "#value > 35000",
            measure: "Price",
            aggregation: "sum",
            format: {
              backgroundColor: "#00A45A",
              color: "#FFFFFF",
              fontFamily: "Arial",
              fontSize: "12px",
            },
          },
          {
            formula: "#value < 2000",
            measure: "Price",
            aggregation: "sum",
            format: {
              backgroundColor: "#df3800",
              color: "#FFFFFF",
              fontFamily: "Arial",
              fontSize: "12px",
            },
          },
        ],
        formats: [{
            name: "",
            thousandsSeparator: ",",
            decimalSeparator: ".",
            decimalPlaces: 2,
            nullValue: "-"
          },
          {
            name: "currency",
            currencySymbol: "$"
          }
        ]
      };
    
      constructor() {}
    
      ngOnInit(): void {}
    
      customizeToolbar(toolbar: Flexmonster.Toolbar) {
        toolbar.showShareReportTab = true;
      }
    
      customizeCellFunction(cell: Flexmonster.CellBuilder, data: Flexmonster.CellData) {
        if (data.type === "header" && data.hierarchy?.caption === "Country" &&  data.member?.properties) {
          const name = data.member.properties.CurrencyID;
          cell.addClass("fm-custom-cell");
          let flag;
          if (data.expanded) {
            flag = `<i class="fm-icon fm-expanded-icon" title="Click to collapse"></i>
    <img class="flag-icon" src="https://cdn.flexmonster.com/flags/${name.toLowerCase()}.svg">`;
          } else {
            flag = `<i class="fm-icon fm-collapsed-icon" title="Click to expand"></i>
    <img class="flag-icon" src="https://cdn.flexmonster.com/flags/${name.toLowerCase()}.svg">`;
          }
          cell.text = `<div style="display:flex; align-items:center; font-size:12px; position:relative;">
    ${flag}<span style="margin-left: 2px; line-height: 16px;">${data.member.caption}</span></div>`;
        }
      }
    }
    
    <fm-pivot
      [componentFolder]="'https://cdn.flexmonster.com/'"
      [height]="550"
      [toolbar]="true"
      [report]="report"
      [customizeCell]="customizeCellFunction"
      [shareReportConnection]="{url: 'https://olap.flexmonster.com:9500'}"
      (beforetoolbarcreated)="customizeToolbar($event)"
    >
    </fm-pivot>
    
    .fm-custom-cell {
      display: flex !important;
      align-items: center !important;
      font-size: 12px !important;
    }
    
    .fm-custom-cell .flag-icon {
      width: 21px !important;
      height: 16px !important;
      margin-left: 0 !important;
      margin-right: 2px !important;
    }
    
    #fm-pivot-view .fm-grid-layout .fm-custom-cell.fm-expanded .fm-expanded-icon::before,
    #fm-pivot-view .fm-grid-layout .fm-custom-cell.fm-collapsed .fm-collapsed-icon::before {
      top: -2px;
      height: 16px;
    }
    

    If you want to try the Flexmonster Angular demo, check out our sample Angular project on GitHub.

    What is an Angular pivot table by Flexmonster

    It acts as an engine that automatically aggregates data, allowing users to group, filter, and sort information across multiple dimensions. 

    Flexmonster is more than just a pivot grid - it is a full-cycle reporting tool that offers:

    • Framework compatibility: seamlessly integrates with latest versions of Angular.
    • Ease of integration: add the pivot library to your project in minutes via a comprehensive Angular integration guide or check out our sample Angular project on GitHub
    • Real-time analysis: allows end-users to create interactive pivot tables and charts dynamically.

    Show data from various data sources

    The Flexmonster Angular pivot grid allows you to load and aggregate data from any source:

    Advanced pivot table analytical features

    Designed for deep data exploration, the pivot grid component allows you to:

    • Drag-and-drop to rearrange rows, columns, and measures.
    • Built-in multi-level grouping, filtering, and sorting.
    • Highlight trends with conditional formatting and number formatting.
    • Switch instantly between compact, tabular, and flat views.
    • Use the drill-through feature to view raw data behind any value.
    • Export reports to Excel, PDF, CSV, HTML, or PNG.
    • Save report configurations as JSON or share direct links to collaborate with team members.

    How to integrate a Pivot Table into Angular in 5 minutes:

    1. Install the Flexmonster CLI: Run npm install -g flexmonster-cli.
    2. Add the Angular wrapper following the Angular integration guide or by watching our Angular pivot table integration video tutorial.

    Our component fully supports the latest Angular versions while remaining backward compatible with earlier ones.

    Prev Next