Componente PivotTable — sgcHTML | eSeGeCe

PivotTable

TsgcHTMLComponent_PivotTable — renderize uma tabela dinâmica Bootstrap que agrupa linhas e colunas e agrega medidas com totais de linha, coluna e geral, em Delphi, C++ Builder e .NET.

TsgcHTMLComponent_PivotTable

Declare os campos de agrupamento e as medidas, alimente-o com linhas brutas (ou vincule um dataset) e então leia a propriedade HTML.

Classe do componente

TsgcHTMLComponent_PivotTable

Renderiza

Tabela agregada Bootstrap 5 + totais

Família

Dados & Tabelas

Linguagens

Delphi, C++ Builder, .NET

Declare os campos, adicione linhas, renderize

Adicione RowFields / ColumnFields para agrupar, adicione uma entrada em Measures para cada valor agregado, liste as colunas de origem em DataFields, insira linhas com AddRow e então leia 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

Principais propriedades & métodos

Os membros que você usa com mais frequência.

RowFields / ColumnFields

Cada entrada tem um FieldName e Caption; RowFields agrupa as linhas na lateral esquerda, ColumnFields agrupa as colunas na parte superior.

Measures

Measures.Add retorna um TsgcHTMLPivotMeasure com SourceField, Caption, uma Aggregation (SUM/COUNT/AVERAGE/MIN/MAX) e uma máscara Format opcional.

DataFields / AddRow

DataFields lista as colunas de origem brutas posicionalmente; AddRow(aValues) adiciona uma linha seguindo essa ordem.

Vinculação a dataset

LoadFromDataSet(aDataSet) lê apenas os campos referenciados por RowFields, ColumnFields e Measures diretamente de um TDataSet.

Totais

ShowRowTotals, ShowColumnTotals e ShowGrandTotal ativam, cada um, uma linha/coluna de resumo; TotalText os rotula.

Estilo da tabela

Striped, Bordered, Hover e Compact estilizam a tabela Bootstrap; EmptyCellText preenche buckets vazios; HTML retorna a tabela finalizada.

Continue explorando

Ajuda onlineReferência completa da API e guia de uso para este componente.
Todos os Componentes sgcHTMLExplore a matriz completa de recursos com mais de 80 componentes.
Baixar Versão de Avaliação GratuitaA avaliação de 30 dias inclui os projetos de demonstração 60.HTML.
PreçosLicenças Single, Team e Site com código-fonte completo.

Pronto para Começar?

Baixe a versão de avaliação gratuita e comece a construir UIs web em Delphi, C++ Builder e .NET.