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';
Since v2.6.3 double-quote character ( " ) can be used to quote field name if one contain spaces, commas or other non-alphanumeric character. For example:
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.
This code can be used to sort data in TDBGrid component by particular column when user clicks on its title.
procedure TForm1.DBGrid1TitleClick(Column: TColumn);
begin
//if column already sorted lets sort it in reverse order
if mySQLTable1.SortFieldNames = Column.FieldName then
mySQLTable1.SortFieldNames := Column.FieldName + ' DESC'
else
mySQLTable1.SortFieldNames := Column.FieldName;
end;