Skip to main content

How to Add an Unbound Field to Supply Additional Data

  • 2 minutes to read

The following code snippet adds two unbound fields which represent a discount and discount value for orders. For analyzing purposes, a discount of 10% is applied to all the orders in a bound data source. A discount value is calculated for each payment referenced by the DBPivotGridPaymentAmount field.

var
  I: Integer;
  ADiscountField: TcxPivotGridField;
begin
  DBPivotGrid.BeginUpdate;
  ADiscountField := DBPivotGrid.CreateField;
  with ADiscountField do
  begin
    Caption := 'Discount';
    DisplayFormat := '0.0%';
    SummaryType := stMin;
    Visible := True;
    Area := faData;
    DataBinding.ValueType := 'Float';
    for I := 0 to PivotGrid.DataController.RecordCount - 1 do
      Values[I] := 10;
  end;
  with DBPivotGrid.CreateField do
  begin
    Caption := 'Discount value';
    SummaryType := stSum;
    Visible := True;
    Area := faData;
    DataBinding.ValueType := 'Currency';
    with PivotGrid.DataController do
      for I := 0 to RecordCount - 1 do
        Values[I] := Values[I, DBPivotGridPaymentAmount.Index] *
          Values[I, ADiscountField.Index] / 100;
  end;
  DBPivotGrid.EndUpdate;
end;
See Also