TTMSFNCDataGrid.Sort Method
Sorts all data rows by the specified column and direction.
API unit family: TMSFNCDataGrid
Declaring type: TTMSFNCDataGrid
Inherited from: TTMSFNCCustomDataGrid
Overloads
Overload 1
Sorts all data rows by the specified column and direction.
procedure Sort(AColumn: Integer; ADirection: TTMSFNCDataGridSortDirection); reintroduce; overload;
HIDESBASE void __fastcall Sort(int AColumn, TTMSFNCDataGridSortDirection ADirection)/* overload */;
Parameters
| Name | Description |
|---|---|
AColumn |
Zero-based column index to sort by. |
ADirection |
Sort direction (ascending or descending). |
Overload 2
Sorts rows within the given row range by the specified column and direction.
procedure Sort(AColumn: Integer; ADirection: TTMSFNCDataGridSortDirection; AFromRow, AToRow: Integer); reintroduce; overload;
HIDESBASE void __fastcall Sort(int AColumn, TTMSFNCDataGridSortDirection ADirection, int AFromRow, int AToRow)/* overload */;
Parameters
| Name | Description |
|---|---|
AColumn |
Zero-based column index to sort by. |
ADirection |
Sort direction (ascending or descending). |
AFromRow |
First row index of the range to sort. |
AToRow |
Last row index of the range to sort. |
Overload 3
Performs a multi-column sort with optional custom compare and sort options callbacks.
procedure Sort(AColumns: TArray<Integer>; ADirections: TArray<TTMSFNCDataGridSortDirection>; ACustomCompareCallback: TTMSFNCDataGridDataCustomCompareCallback = nil; ASortOptionsCallback: TTMSFNCDataGridDataGetSortOptionsCallback = nil); reintroduce; overload;
HIDESBASE void __fastcall Sort(System::DynamicArray<int> AColumns, System::DynamicArray<TTMSFNCDataGridSortDirection> ADirections, Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataCustomCompareCallback ACustomCompareCallback = Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataCustomCompareCallback(), Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataGetSortOptionsCallback ASortOptionsCallback = Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataGetSortOptionsCallback())/* overload */;
Parameters
| Name | Description |
|---|---|
AColumns |
Array of zero-based column indices defining the sort priority. |
ADirections |
Array of sort directions corresponding to AColumns. |
ACustomCompareCallback |
Optional callback for custom value comparison. |
ASortOptionsCallback |
Optional callback to supply per-column sort options. |
Overload 4
Performs a multi-column sort over a limited row range with optional callbacks.
procedure Sort(AColumns: TArray<Integer>; ADirections: TArray<TTMSFNCDataGridSortDirection>; AFromRow, AToRow: Integer; ACustomCompareCallback: TTMSFNCDataGridDataCustomCompareCallback = nil; ASortOptionsCallback: TTMSFNCDataGridDataGetSortOptionsCallback = nil); reintroduce; overload;
HIDESBASE void __fastcall Sort(System::DynamicArray<int> AColumns, System::DynamicArray<TTMSFNCDataGridSortDirection> ADirections, int AFromRow, int AToRow, Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataCustomCompareCallback ACustomCompareCallback = Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataCustomCompareCallback(), Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataGetSortOptionsCallback ASortOptionsCallback = Fmx::Tmsfncdatagriddata::_di_TTMSFNCDataGridDataGetSortOptionsCallback())/* overload */;
Parameters
| Name | Description |
|---|---|
AColumns |
Array of zero-based column indices defining the sort priority. |
ADirections |
Array of sort directions corresponding to AColumns. |
AFromRow |
First row index of the range to sort. |
AToRow |
Last row index of the range to sort. |
ACustomCompareCallback |
Optional callback for custom value comparison. |
ASortOptionsCallback |
Optional callback to supply per-column sort options. |
Usage examples
Enable column sorting and apply an initial sort
Switch on sorting, then sort the grid ascending by column 1 on form create.
procedure TForm1.FormCreate(Sender: TObject);
begin
Grid.Options.IO.StartColumn := 1;
Grid.Options.IO.StartRow := 1;
Grid.LoadFromCSVData('CARS.csv');
Grid.Cells[1, 0] := 'Brand';
Grid.Cells[2, 0] := 'Type';
Grid.AutoNumberColumn(0, 1);
// Allow the user to sort by clicking column headers
Grid.Options.Sorting.Enabled := True;
// Initial sort: by Brand, ascending
Grid.Sort(1, gsdAscending);
end;
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Grid->Options->IO->StartColumn = 1;
Grid->Options->IO->StartRow = 1;
Grid->LoadFromCSVData("CARS.csv");
Grid->Strings[1][0] = "Brand";
Grid->Strings[2][0] = "Type";
Grid->AutoNumberColumn(0, 1);
// Allow the user to sort by clicking column headers
Grid->Options->Sorting->Enabled = true;
// Initial sort: by Brand, ascending
Grid->Sort(1, gsdAscending);
}