procedure TFrameModelo.UniDBGrid1ColumnSort(Column: TUniDBGridColumn; Direction: Boolean);
begin
if Direction then
TFdquery(DsPes.DataSet).IndexName := Column.FieldName+'_index_asc'
else
TFdquery(DsPes.DataSet).IndexName := Column.FieldName+'_index_des';
end;
procedure TFrameModelo.UniFrameCreate(Sender: TObject);
var
I: Integer;
IndexnameAsc : string;
IndexnameDes : string;
begin
if Assigned(DsPes.DataSet) then
begin
// TFDQuery(DsPes.DataSet).IndexDefs.Clear;
for I := 0 to TFDQuery(DsPes.DataSet).FieldCount-1 do
begin
IndexnameAsc := TFDQuery(DsPes.DataSet).Fields[I].FieldName+'_index_asc';
IndexnameDes := TFDQuery(DsPes.DataSet).Fields[I].FieldName+'_index_des';
if TFDQuery(DsPes.DataSet).Indexes.FindIndex(IndexnameAsc) = nil then
begin
with TFDQuery(DsPes.DataSet).Indexes.Add do
begin
Name := IndexnameAsc;
Fields := TFDQuery(DsPes.DataSet).Fields[I].FieldName;
Active := True;
end;
end;
if TFDQuery(DsPes.DataSet).Indexes.FindIndex(IndexnameDes) = nil then
begin
with TFDQuery(DsPes.DataSet).Indexes.Add do
begin
Name := IndexnameDes;
Fields := TFDQuery(DsPes.DataSet).Fields[I].FieldName;
Options := [soDescending];
Active := True;
end;
end;
end;
end;
for I := 0 to UniDBGrid1.Columns.Count - 1 do
UniDBGrid1.Columns[i].Sortable := True;
end;
try this code.