DAC for MySQL

TDataSet.Properties.SortFieldNames

Previous Next

Specifies field names and sorting order to sort opened dataset by these fields on the client side without refetching data from server.

Syntax:

property SortFieldNames : string;

Description:

Set SortFieldNames to establish or change the list of fields on which the dataset is sorted. Set sort to the name of a single field or to a comma-separated list of fields. Every field name can be followed by the keyword 'ASC' or 'DESC' to specify a sort direction for the field. If one of these keywords is not used, the default sort direction for the field is ascending ('ASC'). For example:

mySQLQuery1.SortFieldNames := 'ID, Name DESC, ColorValue ASC';

If dataset is opened setting this property to some string causes sorting of dataset immediately. If dataset is closed (Active = false) it will be sorted by this fields after opening. This property can also be used at Design-time.

Example of usage:

This code can be used to sort data in TDBGrid component by particular column when user clicks on it title.

procedure TForm1.DBGrid1TitleClick(Column: TColumn);
begin
   mySQLTable1. SortFieldNames := Column.FieldName + ' ASC';
end;