Skip to main content
Table of Contents

TTMSFNCDataGrid.Group Method

Groups the data rows by the values of a column.

API unit family: TMSFNCDataGrid Declaring type: TTMSFNCDataGrid Inherited from: TTMSFNCCustomDataGrid

Overloads

Overload 1

Groups the data rows by the values of a column.

FMX.TMSFNCDataGrid.hppPascalC++
procedure Group(AColumn: Integer); overload;
void __fastcall Group(int AColumn)/* overload */;

Remarks

Rows are sorted on the column and a collapsible node row is inserted above every distinct value. The grouped column is hidden when Options.Grouping.HideColumns is True (False by default). OnGroup is only fired for grouping through the header visual grouping zone, not by this method.

Nothing happens (a log message is emitted) when the grid is already grouped (call Ungroup first) or when the data area contains merged cells.

Parameters

Name Description
AColumn Zero-based column index to group by.

Examples

Pascal
Grid.Group(2);

Overload 2

Groups the data rows on several columns, one nesting level per column.

FMX.TMSFNCDataGrid.hppPascalC++
procedure Group(AColumns: TArray<Integer>; ASortColumns: TArray<Integer> = nil; ACustomGroupCallback: TTMSFNCDataGridDataGetCustomGroupCallback = nil; ACustomCompareCallback: TTMSFNCDataGridDataCustomCompareCallback = nil; AGroupOptionsCallback: TTMSFNCDataGridDataGetGroupOptionsCallback = nil; ASortOptionsCallback: TTMSFNCDataGridDataGetSortOptionsCallback = nil); overload;
void __fastcall Group(System::DynamicArray<int> AColumns, System::DynamicArray<int> ASortColumns = System::DynamicArray<int>(), Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataGetCustomGroupCallback ACustomGroupCallback = Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataGetCustomGroupCallback(), Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataCustomCompareCallback ACustomCompareCallback = Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataCustomCompareCallback(), Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataGetGroupOptionsCallback AGroupOptionsCallback = Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataGetGroupOptionsCallback(), Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataGetSortOptionsCallback ASortOptionsCallback = Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataGetSortOptionsCallback())/* overload */;

Remarks

The same preconditions as the single-column overload apply: the grid must not be grouped yet and the data area must not contain merged cells.

Parameters

Name Description
AColumns Zero-based column indexes to group by, outermost level first.
ASortColumns Optional columns used to sort the rows inside each group.
ACustomGroupCallback Optional callback that returns a custom group key for a value (for example to group dates by month); when nil, OnGetCustomGroup is used.
ACustomCompareCallback Optional callback for custom value comparison; when nil, OnCustomCompare is used.
AGroupOptionsCallback Optional callback that adjusts the grouping options per level; when nil, OnGetGroupOptions is used.
ASortOptionsCallback Optional callback that adjusts the sort options; when nil, OnGetSortOptions is used.

Overload 3

Groups the data rows as described by a group info record, for example one read from GroupInfo earlier.

FMX.TMSFNCDataGrid.hppPascalC++
procedure Group(AGroupInfo: TTMSFNCDataGridDataGroupInfo; ACustomGroupCallback: TTMSFNCDataGridDataGetCustomGroupCallback = nil; ACustomCompareCallback: TTMSFNCDataGridDataCustomCompareCallback = nil; AGroupOptionsCallback: TTMSFNCDataGridDataGetGroupOptionsCallback = nil; ASortOptionsCallback: TTMSFNCDataGridDataGetSortOptionsCallback = nil); overload;
void __fastcall Group(const TTMSFNCDataGridDataGroupInfo &AGroupInfo, Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataGetCustomGroupCallback ACustomGroupCallback = Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataGetCustomGroupCallback(), Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataCustomCompareCallback ACustomCompareCallback = Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataCustomCompareCallback(), Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataGetGroupOptionsCallback AGroupOptionsCallback = Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataGetGroupOptionsCallback(), Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataGetSortOptionsCallback ASortOptionsCallback = Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataGetSortOptionsCallback())/* overload */;

Parameters

Name Description
AGroupInfo Grouping description: the group columns and optional sort columns.
ACustomGroupCallback Optional callback to produce a custom group key string.
ACustomCompareCallback Optional callback for custom value comparison during sort.
AGroupOptionsCallback Optional callback to supply per-column grouping options.
ASortOptionsCallback Optional callback to supply per-column sort options.

Usage examples

Group rows by Brand, sum the Kw column, and average the Cyl column. Toggle expand/collapse with one call.

Group by a column with a summary footerPascalC++
procedure TForm1.GroupButtonClick(Sender: TObject);
begin
  // Visual settings
  Grid.Options.Grouping.MergeHeader := True;
  Grid.Options.Grouping.Summary := True;

  // Group by column 1 (Brand)
  Grid.Group(1);

  // Add aggregations on the grouped data
  Grid.GroupSum(6);          // sum of Kw column per group
  Grid.GroupAverage(5);      // average of Cyl column per group
end;

procedure TForm1.UngroupButtonClick(Sender: TObject);
begin
  Grid.UnGroup;
end;

procedure TForm1.ToggleExpandClick(Sender: TObject);
begin
  if AllExpanded then
    Grid.CollapseAllNodes
  else
    Grid.ExpandAllNodes;
  AllExpanded := not AllExpanded;
end;
void __fastcall TForm1::GroupButtonClick(TObject *Sender)
{
  // Visual settings
  Grid->Options->Grouping->MergeHeader = true;
  Grid->Options->Grouping->Summary = true;

  // Group by column 1 (Brand)
  Grid->Group(1);

  // Add aggregations on the grouped data
  Grid->GroupSum(6);          // sum of Kw column per group
  Grid->GroupAverage(5);      // average of Cyl column per group
}

void __fastcall TForm1::UngroupButtonClick(TObject *Sender)
{
  Grid->Ungroup();
}

void __fastcall TForm1::ToggleExpandClick(TObject *Sender)
{
  if (AllExpanded)
    Grid->CollapseAllNodes();
  else
    Grid->ExpandAllNodes();
  AllExpanded = !AllExpanded;
}

Read the related guide