Sign in Join
Wiki copytemporary

TdxDBGridController: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11## About
22
33TdxDBGridController is a non visual component with no dependencies providing added functionalities for the TDBGrid object.
44
55Download: <https://gitlab.com/lazaruscomponent/dbgridcontroller>
66
77Demo project: <https://gitlab.com/lazaruscomponent/dbgridcontroller/-/tree/master/demo>
88
99Licenses: MPL 2.0 or LGPL.
1010
11-<img src="TdxDBGridController_200.png" title="|" width="32" alt="|" /> TdxDBGridController component
11+![\|](/wiki-images/5/5c/TdxDBGridController_200.png) TdxDBGridController component
1212
1313![](/wiki-images/c/cb/TdxDBGridController_DataControl.png)
1414
1515TdxDBGridController will be installed in the Data Controls tab
1616
1717## Features
1818
1919### Main functionalities
2020
2121A grid controller that provides extra features to your existing TDBGrid.
2222
2323- Searching expression in the grid
2424- Searching expression in column
2525- Column filter editor
2626- Datetime editor, memo editor and lookup editor
2727- Saving the current filter view (JSON)
2828- Multi column sorting
2929- Column chooser editor
3030- Column grouping visual separator on one level
3131- No data indicator
3232- Footer and aggregation on columns
3333- Perform 50000 records under a second
3434
3535### TDBGrid events to achive the task
3636
3737For all these events the inherited events are called before they are triggered, it is possible that these cause unexpected behavior, it is therefore necessary to validate the relevance of keeping them or at least validating their execution.
3838
3939- OnDrawColumnTitle
4040- OnDrawColumnCell
4141- OnEditButtonClick
4242- OnGetCellHint
4343- OnKeyDown
4444- OnMouseMove
4545- OnMouseDown
4646- OnTitleClick
4747
4848### Overriden event of the dataset linked to the TDBGrid
4949
5050If an OnFilterRecord event is used by the dataset, it will be override by the builtin event of the controller, no inheritance is taken into account in this case. Need this to achive the filtering with no interference.
5151
5252- OnFilterRecord
5353
5454### TdxDBGridController events
5555
5656| | |
5757|----|----|
5858| OnAfterFilterGrid | Event handler triggered after filter execution |
5959| OnAfterSortColumn | Event handler triggered after sorting a column |
6060| OnAggregation | Event handler to define which column is showing an aggregation |
6161| OnBeforeSortColumn | Event handler triggered before sorting a column |
6262| OnLocalize | Event handler triggered to translate string resources |
6363| OnPrepareLookupDataset | Event handler triggered to prepare the lookup dataset if needed |
6464| OnSortColumn | If your dataset is inherited from **TBufDataset**, **TSQLQuery** (Lazarus), **TMSQuery**, **TMSTable** (Devart), **TZQuery**, **TZTable** (ZeosLib) you don't need to use this event handler, the controller will automatically detect the class and set the **IndexDef**, **IndexFieldNames** or **SortedFields** properties accordingly to the dataset you're using. You can use the SQLOrderBy value to requery your dataset on the db server side if needed. |
6565
6666## Examples
6767
6868### Aggregation example on 2 lines
6969
7070``` pascal
7171Procedure TForm1.dxDBGridController1Aggregation(Sender: TdxDBGridController);
7272Begin
7373 Sender.ColumnPropertyList.ColumnPropertyByName('ProjectManager').FooterAlignment := taRightJustify;
7474 Sender.ColumnPropertyList.ColumnPropertyByName('ProjectManager').FooterDisplayText :=
7575 'Count Distinct : ' + Sender.ColumnPropertyList.Aggregation(agDistinct, 'ProjectManager').AsString;
7676
7777 // Use the FooterPanel property to set the height : dxDBGridControler1.FooterPanel.Height := Self.DBGrid1.DefaultRowHeight * 2;
7878 Sender.ColumnPropertyList.ColumnPropertyByName('OpeningDate').FooterAlignment := taCenter;
7979 Sender.ColumnPropertyList.ColumnPropertyByName('OpeningDate').FooterDisplayText :=
8080 'Min : ' + Sender.ColumnPropertyList.Aggregation(agMin, 'OpeningDate').AsString + Char(13) + Char(10) +
8181 'Max : ' + Sender.ColumnPropertyList.Aggregation(agMax, 'OpeningDate').AsString;
8282End;
8383‎
8484```
8585
8686### Localization
8787
8888This is an example, French translation of some of the component string resources:
8989
9090``` pascal
9191Procedure TForm1.dxDBGridController1Localize(Sender: TObject; Component: TComponent; ID_Ressource: String; Var Translation: String);
9292Begin
9393 If ID_Ressource = msg_search Then
9494 Translation := 'Recherche...'
9595 Else If ID_Ressource = msg_first Then
9696 Translation := 'Aller au début'
9797 Else If ID_Ressource = msg_prior Then
9898 Translation := 'Précédent'
9999 Else If ID_Ressource = msg_next Then
100100 Translation := 'Suivant'
101101 Else If ID_Ressource = msg_last Then
102102 Translation := 'Aller à la fin'
103103 Else If ID_Ressource = msg_add Then
104104 Translation := 'Ajouter'
105105 Else If ID_Ressource = msg_delete Then
106106 Translation := 'Détruire'
107107 Else If ID_Ressource = msg_edit Then
108108 Translation := 'Éditer'
109109 Else If ID_Ressource = msg_save Then
110110 Translation := 'Enregistrer'
111111 Else If ID_Ressource = msg_cancel Then
112112 Translation := 'Annuler'
113113 Else If ID_Ressource = msg_refresh Then
114114 Translation := 'Actualiser'
115115 Else If ID_Ressource = msg_btncancel Then
116116 Translation := 'Annuler'
117117 Else If ID_Ressource = msg_of Then
118118 Translation := 'de'
119119 Else If ID_Ressource = msg_nodata Then
120120 Translation := 'Aucune donnée trouvée!'
121121 Else If ID_Ressource = msg_columnchooser Then
122122 Translation := 'Sélectionner les colonnes...'
123123 Else If ID_Ressource = msg_clearselection Then
124124 Translation := 'Annuler sélection'
125125 Else If ID_Ressource = msg_selectall Then
126126 Translation := 'Tout sélectionner'
127127 Else If ID_Ressource = msg_sortingasc Then
128128 Translation := 'Trier en mode croissant'
129129 Else If ID_Ressource = msg_sortingdesc Then
130130 Translation := 'Trier en mode décroissant';
131131End;
132132‎
133133```
134134
135135List of ressourcestring used by the TdxDBGridController
136136
137137- msg_search = 'Search...';
138138- msg_first = 'First';
139139- msg_prior = 'Prior';
140140- msg_next = 'Next';
141141- msg_last = 'Last';
142142- msg_add = 'Add';
143143- msg_delete = 'Delete';
144144- msg_edit = 'Edit';
145145- msg_save = 'Save';
146146- msg_cancel = 'Cancel';
147147- msg_refresh = 'Refresh';
148148- msg_btncancel = 'Cancel';
149149- msg_btnok = 'OK';
150150- msg_of = 'of';
151151- msg_nodata = 'No Data Found!';
152152- msg_columnchooser = 'Column Chooser...';
153153- msg_clearselection = 'Clear Selection';
154154- msg_selectall = 'Select All';
155155- msg_sortingasc = 'Sort by ascending order';
156156- msg_sortingdesc = 'Sort by descending order';
157157
158158## Screenshots
159159
160160### Global search
161161
162162![](/wiki-images/7/75/TdxDBGridController_SearchGrid.png)
163163
164164### Multi sort
165165
166166A Ctrl+Left clic is use to performe a multi column sorting, the index will appear under the sort indicator.
167167
168168![](/wiki-images/1/13/TdxDBGridController_MultiSort.png)
169169
170170### Column filter
171171
172172Once you have focused on the grid you can have access to the column filter by clicking the filter icon or with the default shortcut Ctrl+J, this shortcut could be changed with the ColumnFilterShortCut property.
173173
174174![](/wiki-images/1/1b/TdxDBGridController_ColumnFilter.png)
175175
176176### Column search and aggregation
177177
178178It is not mandatory to use the footer panel to display the aggregation, you can use any other control at your convenience. The values are calculated and set in the OnAggregation event. In this example, the FooterPanel height of the TdxDBGridController was set to Self.DBGrid1.DefaultRowHeight * 2 in order to display the result on 2 lines.
179179
180180![](/wiki-images/c/cc/TdxDBGridController_SearchAndAggregation.png)
181181
182182### TdxDBGridController properties
183183
184184![](/wiki-images/6/6c/TdxDBGridController_Properties.png)
185185
186186# See also
187187
188188- [[doc:lcl/dbgrids/tdbgrid.html|TDBGrid doc]]
189189- [[TDBGrid]]
190190- [[TStringGrid]]
191191- [[Grids Reference Page]]
192192
193193---
194194*From the Free Pascal wiki, page "TdxDBGridController", as it stood on 2023-01-23 after a change by Five, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history