Customizing grid footer

AdminAbout 3 min

Customizing grid footer

TDBGridEh can display special row (footer) or rows at bottom part.

Use FooterRowCount property to specify the number of footer rows in the grid. Use Footer or Footers property of TColumnEh object to specify information which needs to show in footer cells. The Footers property is useful when you have more than one footer rows. Footers are a collection of TColumnFooterEh objects. Information from i-th element of collection will be shown in i-th row of footer. In footer cell, it is possible to show: Sum value for the specific field, records count, the value of a specific field or static text. Use Footer.ValueType or Footers[i].ValueType property to specify which type of value will be shown in the footer cell. If ValueType = fvtStaticText, then you also need to set Value property to specify text which will be shown. If ValueType = fvtFieldValue, then you need to set property FieldName to specify the field, value of which will be shown. To force grid to calculate total values you need to activate SumList (Set DBGridEh.SumList.Active to True value). Set TColumnFooterEh.ValueType to fvtSum to show sum value of the column field in the footer cell, you can also specify Column.Footer.FieldName to calculate total value of the other field. Set ValueType to fvtCount to force grid to display count of records in the footer cell.

Use the sub-properties of TDBGridEh.FooterParams property to Customize the footer of the grid:

Color: TColor

Specifies the background color for the footer color

FillStyle: TGridCellFillStyleEh

Specifies the style of filling the footer cells

Font: TFont

Controls the font in which the title cells displays its data.

ParentFont: Boolean

Determines where a control looks for its font information.

RowHeight: Integer

Specifies the height of footer row in text lines

RowLines: Integer

Specifies the height of footer row in text lines Full row height = height in pixels of RowLines + RowHeight.

HorzLineColor: TColor

Color of the horizontal lines in the footer area.

HorzLines: Boolean

Presence of horizontal lines in the footer area.

VertLineColor: TColor

Color vertical lines in the footer area.

VertLines: Boolean

Presence of vertical lines in the footer area.

The SumList property includes the following subproperties:

Active: Boolean

Set this property to activate the object SumList. SumList used to calculate aggregate values in the footer of the grid.

ExternalRecalc: Boolean

The property specifies that the summation is an external method implemented in the DBGridEh.OnSumListRecalcAll event handler.

VirtualRecords: Boolean

Set this property to True to correctly calculate the positions of the vertical scrollbars for datasets that do not support or incorrectly returns the number of records through the property `DataSet.RecNo`.

DBGridEh events, related to the calculation of aggregate values in SumList'e:

OnSumListRecalcAll

The event is called when DBGridEh.SumList.ExternalRecalc = True. In the event handler is necessary to calculate the aggregate amount for the items in the collection and fill DBGridEh.SumList.SumCollection value DBGridEh.SumList.SumCollection[i].SumValue.

OnSumListAfterRecalcAll

The event is called after counting all aggregated values through SumList.

TColumnEh.Footer and TSolumnEh.Footers[i] elements have TColumnFooterEh type and contain the following properties:

Alignment: TAlignment

Alignment of a summed value in the cell footer.

Color: TColor

Color of a cell footer.

DisplayFormat: String

The format for displaying numbers

EndEllipsis: Boolean

Display ellipsis if text does not fit in a cell grid

FieldName: String

Name of the field to which it applies the aggregate function of certain properties ValueType

Font: TFont

Font of a cell footer

ToolTips: Boolean

Whether to display the tooltip window with a full text of the cell when user move the mouse on footer cell if the text does not fit into the cell.

Value: String

Static text that is displayed in the cell when a Footer.ValueType = fvtStaticText

property SumValue: Variant

Aggregated value as Variant

ValueType: TFooterValueType

Type of output value, or summing function. The property may comprise the following values:

fvtNon, fvtSum, fvtAvg, fvtCount, fvtFieldValue, fvtStaticText , fvtMin, fvtMax


WordWrap: Boolean

Wrap text, if it does not fit on one line in a footer cell.

Use DBGridEh.OnGetFooterParams event in order to control the parameters of the cell footer draw operation.

procedure TForm2.DBGridEh2GetFooterParams(Sender: TObject; DataCol,
  Row: Integer; Column: TColumnEh; AFont: TFont; var Background: TColor;
  var Alignment: TAlignment; State: TGridDrawState; var Text: string);
begin

end;

In the event you can change property values AFont, Background, Alignment, Text to change the text and text fortmat footer cell before rendering.

Use the following methods and properties when using the footer:


function TColumnEh.ColumnUsedFooter(Index: Integer): TColumnFooterEh;

Get a reference to the TColumnFooterEh object, which contains the properties used to display the value in the footer cell. The Index parameter must contain the index of the row in the grid footer section.


function TDBGridEh.GetFooterValue(Footer: TColumnFooterEh; Column: TColumnEh): String; 

The method returns the footer value as a string for a specific column. The Footer parameter specifies a TColumnFooterEh object. The Column parameter specifies the column for which the footer value should be obtained.

Last update:
Contributors: dmitrybv