Bueno como vi que en la parte de trucos no funcionaba para componentes de dbExpress, le pregunte a google y me respondio XD.
Este código pertenece al siguiente
sitio
Código que realiza el ordenamiento:
Código Delphi
[-]
unit f_Varios;
interface
uses
TypInfo, DBClient, DB;
function SortCustomClientDataSet(DataSet: TClientDataSet;const FieldName: String): Boolean;
implementation
function SortCustomClientDataSet(DataSet: TClientDataSet;const FieldName: String): Boolean;
var
i: Integer;
IndexDefs: TIndexDefs;
IndexName: String;
IndexOptions: TIndexOptions;
begin
Result := False;
if IsPublishedProp(DataSet, 'IndexDefs') then
IndexDefs := GetObjectProp(DataSet, 'IndexDefs') as TIndexDefs
else
Exit;
if IsPublishedProp(DataSet, 'IndexName') then
IndexName := GetStrProp(DataSet, 'IndexName')
else
Exit;
IndexDefs.Update;
if DataSet.Fields.FindField(FieldName) = nil then Exit;
if IndexName = FieldName + '__IdxA' then
begin
IndexName := FieldName + '__IdxD';
IndexOptions := [ixDescending];
end
else
begin
IndexName := FieldName + '__IdxA';
IndexOptions := [];
end;
for i := 0 to Pred(IndexDefs.Count) do
begin
if IndexDefs[i].Name = IndexName then
begin
Result := True;
Break
end; end; if not Result then
begin
DataSet.AddIndex(IndexName, FieldName,IndexOptions);
Result := True;
end; SetStrProp(DataSet, 'IndexName', IndexName);
end;
Código para utilizar el ordenamiento:
Código Delphi
[-]
procedure TForm1.DBGrid1TitleClick(Column: TColumn);
begin
inherited;
SortCustomClientDataset(ClientDataSet1,Column.FieldName);
end;
Saludos