PivotTable
TsgcHTMLComponent_PivotTable — 渲染一个 Bootstrap 数据透视表,对行和列进行分组,并通过行小计、列小计和总计汇总度量值,适用于 Delphi、C++ Builder 和 .NET。
TsgcHTMLComponent_PivotTable — 渲染一个 Bootstrap 数据透视表,对行和列进行分组,并通过行小计、列小计和总计汇总度量值,适用于 Delphi、C++ Builder 和 .NET。
声明分组字段和度量值,输入原始行数据(或绑定数据集),然后读取 HTML 属性。
添加用于分组的 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
您最常使用的成员。
每个条目都有 FieldName 和 Caption;RowFields 沿左侧对行进行分组,ColumnFields 沿顶部对列进行分组。
Measures.Add 返回一个 TsgcHTMLPivotMeasure,包含 SourceField、Caption、一个 Aggregation(SUM/COUNT/AVERAGE/MIN/MAX)以及可选的 Format 格式化字符串。
DataFields 按位置列出原始源列;AddRow(aValues) 按该顺序追加一行。
LoadFromDataSet(aDataSet) 直接从 TDataSet 中只读取 RowFields、ColumnFields 和 Measures 所引用的字段。
ShowRowTotals、ShowColumnTotals 和 ShowGrandTotal 分别切换一行/一列汇总;TotalText 为其命名标签。
Striped、Bordered、Hover 和 Compact 设置 Bootstrap 表格的样式;EmptyCellText 填充空单元格;HTML 返回完成的表格。