PivotTable 组件 — sgcHTML | eSeGeCe

PivotTable

TsgcHTMLComponent_PivotTable — 渲染一个 Bootstrap 数据透视表,对行和列进行分组,并通过行小计、列小计和总计汇总度量值,适用于 Delphi、C++ Builder 和 .NET。

TsgcHTMLComponent_PivotTable

声明分组字段和度量值,输入原始行数据(或绑定数据集),然后读取 HTML 属性。

组件类

TsgcHTMLComponent_PivotTable

渲染为

Bootstrap 5 汇总表格 + 总计

语言

Delphi, C++ Builder, .NET

声明字段、添加行,渲染它

添加用于分组的 RowFields / ColumnFields,为每个汇总值添加一个 Measures 条目,在 DataFields 中列出源列,用 AddRow 推送行,然后读取 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

关键属性与方法

您最常使用的成员。

行字段 / 列字段

每个条目都有 FieldNameCaptionRowFields 沿左侧对行进行分组,ColumnFields 沿顶部对列进行分组。

度量值

Measures.Add 返回一个 TsgcHTMLPivotMeasure,包含 SourceFieldCaption、一个 Aggregation(SUM/COUNT/AVERAGE/MIN/MAX)以及可选的 Format 格式化字符串。

数据字段 / 添加行

DataFields 按位置列出原始源列;AddRow(aValues) 按该顺序追加一行。

数据集绑定

LoadFromDataSet(aDataSet) 直接从 TDataSet 中只读取 RowFieldsColumnFieldsMeasures 所引用的字段。

总计

ShowRowTotalsShowColumnTotalsShowGrandTotal 分别切换一行/一列汇总;TotalText 为其命名标签。

表格样式

StripedBorderedHoverCompact 设置 Bootstrap 表格的样式;EmptyCellText 填充空单元格;HTML 返回完成的表格。

继续探索

在线帮助此组件的完整 API 参考和使用指南。
所有 sgcHTML 组件浏览 80 多个组件的完整功能矩阵。
下载免费试用版30 天试用版附带 60.HTML 演示项目。
价格Single、Team 和 Site 授权,均含完整源代码。

准备好开始了吗?

下载免费试用版,开始在 Delphi、C++ Builder 和 .NET 中构建 Web 界面。