如何在DevExpress PivotGrid中显示运行总计?

时间:2011-07-15 17:41:11

标签: delphi grid devexpress

我需要在DevExpress PivotGrid中显示总数加上最后总数 例如:
取这个值:  3月:25日  四月:10  5月:30

导致:

March   April  May
25      35     65

如何配置我的PivotGrid?

提前致谢。

2 个答案:

答案 0 :(得分:1)

您需要在字段的OnCalculateCustomSummary事件中添加此代码:

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;

这是在该领域的OnGetDisplayText事件中:

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

摘自: http://www.devexpress.com/Support/Center/p/Q90021.aspx

答案 1 :(得分:0)

您应该将Field的RunningTotal属性设置为true。