Buenas yo uso un DBGridEh con DBxpert logro ordenar con el siguiente codigo:
Código Delphi
[-]procedure OrdenaDataSetGridEH(var CDS: TClientDataSet; Column: TColumnEH; var dbgPrin: TDBGridEH);
const
idxDefault = 'DEFAULT_ORDER';
var
strColumn : string;
i : integer;
bolUsed : boolean;
idOptions : TIndexOptions;
begin
strColumn := idxDefault;
if Column.Field.FieldKind in [fkCalculated, fkLookup, fkAggregate, fkInternalCalc] then Exit;
if Column.Field.DataType in [ftBlob, ftMemo] then Exit;
for i := 0 to dbgPrin.Columns.Count -1 do
dbgPrin.Columns[i].Title.Font.Color := clNavy;
bolUsed := (Column.Field.FieldName = CDS.IndexName);
CDS.IndexDefs.Update;
for i := 0 to CDS.IndexDefs.Count - 1 do
begin
if CDS.IndexDefs.Items[i].Name = Column.Field.FieldName then
begin
strColumn := Column.Field.FieldName;
case (CDS.IndexDefs.Items[i].Options = [ixDescending]) of
True : idOptions := [];
False : idOptions := [ixDescending];
end;
end;
end;
if (strColumn = idxDefault) or (bolUsed) then
begin
if bolUsed then
CDS.DeleteIndex(Column.Field.FieldName);
try
if (idOptions <> [ixDescending])
and (idOptions <> []) then
idOptions := [];
CDS.AddIndex(Column.Field.FieldName, Column.Field.FieldName, idOptions,'', '', 0);
strColumn := Column.Field.FieldName;
except
if bolUsed then strColumn := idxDefault;
end;
end;
try
CDS.IndexName := strColumn;
Column.Title.Font.Color := clRed;
Column.Title.Caption := Column.Title.Caption;
Column.Title.Font.Style := [fsbold];
CDS.First;
except
CDS.IndexName := idxDefault;
end;
end;
Ahora cuando a un CDS le creo un campo de tipo lookup el mismo no lo ordena y realmente ya he mirado mucho y no logro entender el porque