I wrote two examples, want DBGRID to be able to sort the title after pressing
How to achieve it? You can not re-SQL orders to SQL SERVER
procedure TForm1.SMDBGrid1TitleClick(Column: TColumn);
begin
(Column.Grid as TSMDBGrid).ClearSort;
with ADOQuery1 do
begin
if RightStr(Sort, 3) = 'ESC' THEN
begin
TSMDBColumn(Column).SortType := stAscending;
Sort := Column.FieldName + ' ASC' ;
end
else
begin
TSMDBColumn(Column).SortType := stDescending ;
Sort := Column.FieldName + ' DESC';
end;
end;
end;
procedure TForm1.SMDBGrid2TitleClick(Column: TColumn);
begin
if UniQuery1.IsEmpty then Exit ;
try
Screen.Cursor := crSQLWait ;
(Column.Grid as TSMDBGrid).ClearSort;
with UniQuery1 do
begin
if RightStr(GetOrderBy, 3) = 'ESC' THEN
begin
TSMDBColumn(Column).SortType := stAscending;
SetOrderBy(Column.FieldName + ' ASC');
end
else
begin
TSMDBColumn(Column).SortType := stDescending ;
SetOrderBy(Column.FieldName + ' DESC' );
end;
Close ;
Open ;
end;
finally
Screen.Cursor := crDefault ;
end;
end;
How to sort Like use ado method
Re: How to sort Like use ado method
To control local dataset sorting, you can use the TUniQuery.IndexFieldNames property. For this, in your sample, replace the line
with
And the line
with
You can read more about the IndexFieldNames property in our online documentation: https://www.devart.com/unidac/docs/?dev ... dnames.htm
Code: Select all
SetOrderBy(Column.FieldName + 'ASC');
Code: Select all
UniQuery1.IndexFieldNames: = Column.FieldName + 'ASC';
Code: Select all
SetOrderBy(Column.FieldName + 'DESC');
Code: Select all
UniQuery1.IndexFieldNames: = Column.FieldName + 'DESC';
Re: How to sort Like use ado method
solved. Thank you!