Pivot Tables for Analytics on Website

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Pivot Table Development for Analytics

A pivot table is a UI for grouping, aggregating, and comparing data in real time. Users drag fields between axes, select metrics, and get needed slices without contacting developers. Excel and Google Sheets are popular precisely for this—embedding similar tools in web apps eliminates export needs.

Architecture

Two fundamentally different approaches:

Client aggregation—all data loaded in browser, pivot calculated in JavaScript. Works up to ~100–200k rows. Fast response on axis manipulation, no server round-trip.

Server aggregation—each config change sends a server request, database calculates aggregates. Mandatory for large volumes. ClickHouse or PostgreSQL with correct indexes return aggregates from millions of rows in hundreds of milliseconds.

Ready-Made Libraries

Before building from scratch, evaluate:

  • react-pivottable—open source, drag-and-drop, multiple renderers (table, bar chart, heatmap). Limited to client processing
  • AG Grid (with row grouping)—enterprise-grade, server mode, huge ecosystem. Paid for advanced features
  • Flexmonster—specialized pivot, connects to OLAP cubes, commercial license

Client Implementation

Pivot core—aggregation function:

type AggregateFunction = 'sum' | 'count' | 'avg' | 'min' | 'max';

interface PivotConfig {
  rows: string[];      // row fields
  cols: string[];      // column fields
  values: string[];    // numeric fields
  aggFn: AggregateFunction;
  filters: Record<string, string[]>;  // field -> allowed values
}

interface PivotResult {
  rowKeys: string[][];
  colKeys: string[][];
  data: Map<string, Map<string, number>>;
}

function computePivot(rawData: Record<string, any>[], config: PivotConfig): PivotResult {
  const { rows, cols, values, aggFn, filters } = config;

  // Apply filters
  const filtered = rawData.filter(row =>
    Object.entries(filters).every(([field, allowed]) =>
      !allowed.length || allowed.includes(String(row[field]))
    )
  );

  // Collect unique row and column keys
  const rowKeySet = new Set<string>();
  const colKeySet = new Set<string>();
  const accumulator = new Map<string, Map<string, number[]>>();

  filtered.forEach(row => {
    const rowKey = rows.map(r => String(row[r] ?? '(empty)')).join('||');
    const colKey = cols.map(c => String(row[c] ?? '(empty)')).join('||');

    rowKeySet.add(rowKey);
    colKeySet.add(colKey);

    const numVal = values.reduce((sum, v) => sum + (Number(row[v]) || 0), 0);

    if (!accumulator.has(rowKey)) accumulator.set(rowKey, new Map());
    const colMap = accumulator.get(rowKey)!;
    if (!colMap.has(colKey)) colMap.set(colKey, []);
    colMap.get(colKey)!.push(numVal);
  });

  // Aggregate
  const aggregated = new Map<string, Map<string, number>>();
  accumulator.forEach((colMap, rowKey) => {
    const row = new Map<string, number>();
    colMap.forEach((vals, colKey) => {
      let result: number;
      switch (aggFn) {
        case 'sum':   result = vals.reduce((a, b) => a + b, 0); break;
        case 'count': result = vals.length; break;
        case 'avg':   result = vals.reduce((a, b) => a + b, 0) / vals.length; break;
        case 'min':   result = Math.min(...vals); break;
        case 'max':   result = Math.max(...vals); break;
      }
      row.set(colKey, result);
    });
    aggregated.set(rowKey, row);
  });

  return {
    rowKeys: Array.from(rowKeySet).sort().map(k => k.split('||')),
    colKeys: Array.from(colKeySet).sort().map(k => k.split('||')),
    data: aggregated,
  };
}

Table Component

Custom pivot UI renders efficiently with virtualized rows:

Key features:

  • Drag-and-drop axis configuration
  • Real-time aggregation
  • Subtotals and grand total
  • Export to CSV/Excel
  • Conditional formatting for values

Server Implementation

For millions of rows, use window functions:

SELECT
  date_trunc('month', created_at)::date AS month,
  category,
  SUM(amount) AS total,
  COUNT(*) AS cnt,
  AVG(amount) AS avg_amount
FROM orders
WHERE created_at > NOW() - INTERVAL '12 months'
GROUP BY 1, 2
ORDER BY 1, 2;

Indexing on (category, created_at) or composite indexes dramatically speeds aggregation.

Timeline

Basic client-side pivot with drag-drop UI—3–5 days. Server implementation with filtering, drill-down, and export—7–10 days.