Вопрос

hello i am new to zeos datasets and i would like my db grid to sort the data in an ascending or descending mode. i am using zeos datasets and a firebird database. i tried searching and this is all i got

procedure TForm1.DBGrid1TitleClick(Column: TColumn);
{$J+}
 const PreviousColumnIndex : integer = -1;
{$J-}
begin
  if DBGrid1.DataSource.DataSet is TCustomADODataSet then
  with TCustomADODataSet(DBGrid1.DataSource.DataSet) do
  begin
    try
      DBGrid1.Columns[PreviousColumnIndex].title.Font.Style :=
      DBGrid1.Columns[PreviousColumnIndex].title.Font.Style - [fsBold];
    except
    end;

Column.title.Font.Style := 
Column.title.Font.Style + [fsBold];
PreviousColumnIndex := Column.Index;

if (Pos(Column.Field.FieldName, Sort) = 1)
and (Pos(' DESC', Sort)= 0) then
  Sort := Column.Field.FieldName + ' DESC'
else
  Sort := Column.Field.FieldName + ' ASC';
  end;
end;

this was from another site but problem is i cant figure out how to use it to the zeos dataset. this is by far what i got

procedure Tdc.DBGrid1TitleClick(Column: TColumn);
begin
      with TZtable (DBGrid1.DataSource.DataSet) do
  Sort := Column.Field.FieldName; + ' ASC'
end;

but frankly i have no idea where to start

Это было полезно?

Решение

procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
  st:ZAbstractRODataset.TSortType;
begin
  st:=ZReadOnlyQuery1.SortType;
  ZReadOnlyQuery1.SortedFields:=Column.FieldName;
  If st = stAscending then ZReadOnlyQuery1.SortType:=stDescending else ZReadOnlyQuery1.SortType:=stAscending;
  DataSource1.DataSet.First;
end;

@bummi thank you

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top