Einzelnen Beitrag anzeigen

Perlsau
(Gast)

n/a Beiträge
 
#3

AW: SQLite + DBGrid + Sortieren über Spalten Click

  Alt 17. Jan 2014, 01:39
Hab ich das richtig interpretiert das man die Datenmenge im DBGrid nicht sortieren kann, sondern das man den SQL Befehl erneut mit der Order By Klausel absetzen muss?
Nicht unbedingt, wenn man wie du UniDac einsetzt. Denn in den zugehörigen Dataset- bwz. Query-Komponenten gibt es das Property IndexFieldNames, dem du einfach den Feldnamen, nach dem sortiert werden soll, als String übergibst. Du kannst auch nach mehreren Feldern sortieren, z.B. erst nach Nachnamen und dann nach Vornamen:

MyQuery.IndexFieldNames := 'Nachname ASC CIS; Vorname DESC';

Da UniDac und IbDac aus derselben Schmiede stammen, gehe ich mal davon aus, daß das, was in meiner IbDac-Hilfe steht, auch für UniDac gilt:

Use the IndexFieldNames property to get or set the list of fields on which the recordset is sorted. Specify the name of each column in IndexFieldNames to use as an index for a table. Ordering of column names is significant. Separate names with semicolon. The specified columns don't need to be indexed. Set IndexFieldNames to an empty string to reset the recordset to the sort order originally used when the recordset's data was first retrieved.
Each field may optionally be followed by the keyword ASC / DESC or CIS / CS / BIN.
Use ASC, DESC keywords to specify a sort direction for the field. If one of these keywords is not used, the default sort direction for the field is ascending.
Use CIS, CS or BIN keywords to specify a sort type for string fields:
CIS - compare without case sensitivity;
CS - compare with case sensitivity;
BIN - compare by character ordinal values (this comparison is also case sensitive).
If a dataset uses a TCustomDAConnection component, the default value of sort type depends on the TCustomDAConnection.Options option of the connection. If a dataset does not use a connection (TVirtualTable dataset), the default is CS.
Read IndexFieldNames to determine the field (or fields) on which the recordset is sorted.
Ordering is processed locally.
Note: You cannot process ordering by BLOB fields.


Wenn man eine Komponente erwirbt, ist es meist nicht verkehrt, sich die Dokumentation dazu anzuschauen, bevor man sie einsetzt.
  Mit Zitat antworten Zitat