2
votes

as far is I know sorting in a ClientDataSet works over the indexDefs. I can add an indexDef, set the field(s) I want to sort, and over the ixDescending property I can define the direction to sort.

I have a ClientDataSet connected to a dataSource which is the source for a DBGrid. When I now insert a new record in the ClientDataSet, it's either inserted at the top of the table (ixDescending = false) or at the bottom of the table (ixDescending = true).

But I want a descending order AND new records should be at the top at the table - not at the bottom. I tried to change the the indexDefs at runtime to achieve this - but without success. Somebody has an idea how to do this?

2

2 Answers

0
votes

When you have inserted a record unless you set values for the indexed fields they are NULL, and sorted accordingly.

0
votes

I don't know of an elegant solution (although I'm a novice in this area.)

Perhaps there's some way for you to create a temporary boolean field in your ClientDataSet... (Maybe a calculated field?) Suppose you name the new field "NewRecord" and include it in your IndexDef so that it is the most significant sort criteria.

In an .OnCreate event, you set it true (which would be 1 internally?). In an .OnPost event you set it false.

If you don't want to depend on the internal representation of booleans, then you could create a string field and put "ZZZZZZZ" in it. Or an integer field and put MaxInt in it.