At First You NEED TO Define Index for Every Column That You Want To Sort:
1W: in IDE
Double Click Your ClientDataSet's Indexdefs Property, Add New, Set "Name" "Fields" "Descfields" Value (for Example: Equal to Column Name)
2W: in Code
With dataset.indexdefs do begin clear; with addindexdef do beg, name: = 'Your column name; fields: =' Your column name '; descfields: =' Your column name '; end;
THEN WRITE CODE IN DBGRIDEH ONTITLECLICK:
case Column.Title.SortMarker of smNoneEh: begin Column.Title.SortMarker: = smDownEh; fTagStateSetDM.cdsData.IndexName: = Column.FieldName; end; smDownEh: begin Column.Title.SortMarker: = smUpEh; fTagStateSetDM.cdsData.IndexFieldNames: = Column.fieldName; End; Smupeh: Begin Column.Title.Sortmarker: = smdowne; ftagstatesetdm.cdsdata.indexName: = column.fieldname; end;