How to sort Like use ado method
Posted: Mon 14 Aug 2017 19:19
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 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;