EPUB | CHM | PDF

TDataSet.Methods.SortBy

Top Previous Next

Sorts opened dataset on client side without refetching data from server.

Syntax:

procedure SortBy(FieldNames : string);

Description:

Call SortBy to sort dataset by particular fields on client side. Field names are case-sensitive and separated by commas. 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.SortBy('ID, Name DESC, ColorValue ASC');

This method affects dataset order only when it is opened, i.e. when Active = True.

The given names are treated like identifiers in an SQL command, that is, they are downcased unless double-quoted.

Example:

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
  PSQLTable1.SortFieldNames := AnsiQuotedStr(Column.FieldName, '"') + ' ASC';
end;

See also: SortFieldNames