开发者

How to show a running total in a DevExpress PivotGrid?

开发者 https://www.devze.com 2023-03-20 10:26 出处:网络
I need to show totals lik开发者_JS百科e the total plus the last total in a DevExpress PivotGrid.

I need to show totals lik开发者_JS百科e the total plus the last total in a DevExpress PivotGrid.

Example:

Taking this values: March: 25

April: 10

May: 30

Resulting in this:

March   April  May
25      35     65

How do I configure my PivotGrid to this?

Thanks in advance.


You need to add this code in the field's OnCalculateCustomSummary event:

procedure TMyForm.cxDBPivotGrid1Field2CalculateCustomSummary(Sender: TcxPivotGridField; ASummary: TcxPivotGridCrossCellSummary);
var
  AColumn: TcxPivotGridGroupItem;
  APrevCrossCell: TcxPivotGridCrossCell;
  APrevCrossCellSummary: TcxPivotGridCrossCellSummary;
begin
  inherited;
  AColumn := ASummary.Owner.Column;
  if (AColumn.Level = -1) then
    // column grand totals
    ASummary.Custom := ASummary.Sum
  else begin
    // all cells, except for column grand totals
    // getting a custom summary calculated for the previous grouping value
    if AColumn.PrevSibling <> nil then begin
      APrevCrossCell        := AColumn.PrevSibling.GetCellByCrossItem(ASummary.Owner.Row);
      APrevCrossCellSummary := APrevCrossCell.SummaryCells[Sender.SummaryIndex];
      ASummary.Custom       := VarToDouble(APrevCrossCellSummary.Custom) + VarToDouble(ASummary.Sum);
    end
    else
      ASummary.Custom       := ASummary.Sum;
  end;
end;

And this in the field's OnGetDisplayText event:

procedure TForm1.cxDBPivotGrid1Field2GetDisplayText(Sender: TcxPivotGridField; ACell: TcxPivotGridDataCellViewInfo; var AText: string);
begin
  inherited;
  AText := VarToStr(ACell.CellSummary.Custom)
end;

Extracted from: http://www.devexpress.com/Support/Center/p/Q90021.aspx


You should set the Field's RunningTotal property to true.

0

精彩评论

暂无评论...
验证码 换一张
取 消