1. Add reference: dbclient
2. Set the DBGRIDEH control properties:
Set the DGHAUTOSORTMARKING attribute to true
Set the TitleButton property of the desired sorting column is true
3.// Table Sort Procedure ORDERGRID (DataSet: TclientDataSet; Orderfield: String);
VAR
i: integer;
Begin
If DataSet.indexfieldNames <> '' THEN
Begin
I: = TclientDataSet (Dataset) .indexdefs.indexof ('i' orderfield);
IF i = -1 Then
Begin
with dataset.indexdefs.addindexdef do
Begin
Name: = 'i' orderfield;
Fields: = ORDERFIELD;
DESCFIELDS: = Orderfield;
END;
END;
DataSet.indexfieldNames: = '';
DataSet.indexName: = 'i' ORDERFIELD;
end
Else
Begin
Dataset.indexName: = '';
DataSet.indexfieldNames: = Orderfield;
END;
END;
4. Tune in the Ontitleclick event in DBGRIDEH
OrderGrid (DM.ClientDataSet, Column.fieldName);