PivotTable Component — sgcHTML | eSeGeCe

PivotTable

TsgcHTMLComponent_PivotTable — render a Bootstrap pivot table that groups rows and columns and aggregates measures with row, column and grand totals, in Delphi, C++ Builder and .NET.

TsgcHTMLComponent_PivotTable

Declare the grouping fields and measures, feed it raw rows (or bind a dataset), then read the HTML property.

Component class

TsgcHTMLComponent_PivotTable

Renders

Bootstrap 5 aggregated table + totals

Family

Data & Tables

Languages

Delphi, C++ Builder, .NET

Declare fields, add rows, render it

Add RowFields / ColumnFields to group by, add a Measures entry per aggregated value, list the source columns in DataFields, push rows with AddRow, then read HTML.

uses
  sgcHTML_Component_PivotTable;

var
  oPivot: TsgcHTMLComponent_PivotTable;
  oMeasure: TsgcHTMLPivotMeasure;
begin
  oPivot := TsgcHTMLComponent_PivotTable.Create(nil);
  try
    oPivot.Caption := 'Revenue by Region and Quarter';

    oPivot.RowFields.Add.FieldName := 'Region';
    oPivot.ColumnFields.Add.FieldName := 'Quarter';

    oMeasure := oPivot.Measures.Add;
    oMeasure.SourceField := 'Amount';
    oMeasure.Caption := 'Revenue';
    oMeasure.Aggregation := paSum;
    oMeasure.Format := '#,##0.00';

    oPivot.DataFields.Add('Region');
    oPivot.DataFields.Add('Quarter');
    oPivot.DataFields.Add('Amount');

    oPivot.AddRow(['EMEA', 'Q1', '12000']);
    oPivot.AddRow(['EMEA', 'Q2', '15500']);
    oPivot.AddRow(['APAC', 'Q1', '9800']);

    WebModule.Response := oPivot.HTML;   // aggregated table + row/column/grand totals
  finally
    oPivot.Free;
  end;
end;

// Or bind it straight to a dataset (reads only RowFields/ColumnFields/Measures fields):
oPivot.LoadFromDataSet(qrySales);
// includes: sgcHTML_Component_PivotTable.hpp

TsgcHTMLComponent_PivotTable *oPivot = new TsgcHTMLComponent_PivotTable(NULL);
try
{
  oPivot->Caption = "Revenue by Region and Quarter";

  oPivot->RowFields->Add()->FieldName = "Region";
  oPivot->ColumnFields->Add()->FieldName = "Quarter";

  TsgcHTMLPivotMeasure *oMeasure = oPivot->Measures->Add();
  oMeasure->SourceField = "Amount";
  oMeasure->Caption = "Revenue";
  oMeasure->Aggregation = paSum;
  oMeasure->Format = "#,##0.00";

  oPivot->DataFields->Add("Region");
  oPivot->DataFields->Add("Quarter");
  oPivot->DataFields->Add("Amount");

  oPivot->AddRow(OPENARRAY(UnicodeString, ("EMEA", "Q1", "12000")));
  oPivot->AddRow(OPENARRAY(UnicodeString, ("APAC", "Q1", "9800")));

  String html = oPivot->HTML;   // aggregated table + row/column/grand totals
}
__finally
{
  delete oPivot;
}
using esegece.sgcWebSockets;

var pivot = new TsgcHTMLComponent_PivotTable();
pivot.Caption = "Revenue by Region and Quarter";

pivot.RowFields.Add().FieldName = "Region";
pivot.ColumnFields.Add().FieldName = "Quarter";

var measure = pivot.Measures.Add();
measure.SourceField = "Amount";
measure.Caption = "Revenue";
measure.Aggregation = TsgcHTMLPivotAggregation.paSum;
measure.Format = "#,##0.00";

pivot.DataFields.Add("Region");
pivot.DataFields.Add("Quarter");
pivot.DataFields.Add("Amount");

pivot.AddRow(new[] { "EMEA", "Q1", "12000" });
pivot.AddRow(new[] { "APAC", "Q1", "9800" });

string html = pivot.HTML;   // aggregated table + row/column/grand totals

Key properties & methods

The members you reach for most often.

RowFields / ColumnFields

Each entry has a FieldName and Caption; RowFields groups rows down the left, ColumnFields groups columns across the top.

Measures

Measures.Add returns a TsgcHTMLPivotMeasure with SourceField, Caption, an Aggregation (SUM/COUNT/AVERAGE/MIN/MAX) and an optional Format picture.

DataFields / AddRow

DataFields lists the raw source columns positionally; AddRow(aValues) appends one row matching that order.

Dataset binding

LoadFromDataSet(aDataSet) reads only the fields referenced by RowFields, ColumnFields and Measures directly from a TDataSet.

Totals

ShowRowTotals, ShowColumnTotals and ShowGrandTotal each toggle a summary row/column; TotalText labels them.

Table styling

Striped, Bordered, Hover and Compact style the Bootstrap table; EmptyCellText fills empty buckets; HTML returns the finished table.

Keep exploring

Online HelpFull API reference and usage guide for this component.
All sgcHTML ComponentsBrowse the full feature matrix of 80+ components.
Download Free TrialThe 30-day trial ships the 60.HTML demo projects.
PricingSingle, Team and Site licenses with full source code.
Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Ready to Get Started?

Download the free trial and start building web UIs in Delphi, C++ Builder and .NET.