Sign in Join
Wiki copytemporary

TdxDBGridController: what changed

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

Title: TdxDBGridController

OldNewLine
1+## About
2+
3+TdxDBGridController is a non visual component with no dependencies providing added functionalities for the TDBGrid object.
4+
5+Download: <https://gitlab.com/lazaruscomponent/dbgridcontroller>
6+
7+Demo project: <https://gitlab.com/lazaruscomponent/dbgridcontroller/-/tree/master/demo>
8+
9+Licenses: MPL 2.0 or LGPL.
10+
11+<img src="TdxDBGridController_200.png" title="|" width="32" alt="|" /> TdxDBGridController component
12+
13+![](/wiki-images/c/cb/TdxDBGridController_DataControl.png)
14+
15+TdxDBGridController will be installed in the Data Controls tab
16+
17+## Features
18+
19+### Main functionalities
20+
21+A grid controller that provides extra features to your existing TDBGrid.
22+
23+- Searching expression in the grid
24+- Searching expression in column
25+- Column filter editor
26+- Datetime editor, memo editor and lookup editor
27+- Saving the current filter view (JSON)
28+- Multi column sorting
29+- Column chooser editor
30+- Column grouping visual separator on one level
31+- No data indicator
32+- Footer and aggregation on columns
33+- Perform 50000 records under a second
34+
35+### TDBGrid events to achive the task
36+
37+For 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.
38+
39+- OnDrawColumnTitle
40+- OnDrawColumnCell
41+- OnEditButtonClick
42+- OnGetCellHint
43+- OnKeyDown
44+- OnMouseMove
45+- OnMouseDown
46+- OnTitleClick
47+
48+### Overriden event of the dataset linked to the TDBGrid
49+
50+If 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.
51+
52+- OnFilterRecord
53+
54+### TdxDBGridController events
55+
56+| | |
57+|----|----|
58+| OnAfterFilterGrid | Event handler triggered after filter execution |
59+| OnAfterSortColumn | Event handler triggered after sorting a column |
60+| OnAggregation | Event handler to define which column is showing an aggregation |
61+| OnBeforeSortColumn | Event handler triggered before sorting a column |
62+| OnLocalize | Event handler triggered to translate string resources |
63+| OnPrepareLookupDataset | Event handler triggered to prepare the lookup dataset if needed |
64+| 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. |
65+
66+## Examples
67+
68+### Aggregation example on 2 lines
69+
70+``` pascal
71+Procedure TForm1.dxDBGridController1Aggregation(Sender: TdxDBGridController);
72+Begin
73+ Sender.ColumnPropertyList.ColumnPropertyByName('ProjectManager').FooterAlignment := taRightJustify;
74+ Sender.ColumnPropertyList.ColumnPropertyByName('ProjectManager').FooterDisplayText :=
75+ 'Count Distinct : ' + Sender.ColumnPropertyList.Aggregation(agDistinct, 'ProjectManager').AsString;
76+
77+ // Use the FooterPanel property to set the height : dxDBGridControler1.FooterPanel.Height := Self.DBGrid1.DefaultRowHeight * 2;
78+ Sender.ColumnPropertyList.ColumnPropertyByName('OpeningDate').FooterAlignment := taCenter;
79+ Sender.ColumnPropertyList.ColumnPropertyByName('OpeningDate').FooterDisplayText :=
80+ 'Min : ' + Sender.ColumnPropertyList.Aggregation(agMin, 'OpeningDate').AsString + Char(13) + Char(10) +
81+ 'Max : ' + Sender.ColumnPropertyList.Aggregation(agMax, 'OpeningDate').AsString;
82+End;
83+‎
84+```
85+
86+### Localization
87+
88+This is an example, French translation of some of the component string resources:
89+
90+``` pascal
91+Procedure TForm1.dxDBGridController1Localize(Sender: TObject; Component: TComponent; ID_Ressource: String; Var Translation: String);
92+Begin
93+ If ID_Ressource = msg_search Then
94+ Translation := 'Recherche...'
95+ Else If ID_Ressource = msg_first Then
96+ Translation := 'Aller au début'
97+ Else If ID_Ressource = msg_prior Then
98+ Translation := 'Précédent'
99+ Else If ID_Ressource = msg_next Then
100+ Translation := 'Suivant'
101+ Else If ID_Ressource = msg_last Then
102+ Translation := 'Aller à la fin'
103+ Else If ID_Ressource = msg_add Then
104+ Translation := 'Ajouter'
105+ Else If ID_Ressource = msg_delete Then
106+ Translation := 'Détruire'
107+ Else If ID_Ressource = msg_edit Then
108+ Translation := 'Éditer'
109+ Else If ID_Ressource = msg_save Then
110+ Translation := 'Enregistrer'
111+ Else If ID_Ressource = msg_cancel Then
112+ Translation := 'Annuler'
113+ Else If ID_Ressource = msg_refresh Then
114+ Translation := 'Actualiser'
115+ Else If ID_Ressource = msg_btncancel Then
116+ Translation := 'Annuler'
117+ Else If ID_Ressource = msg_of Then
118+ Translation := 'de'
119+ Else If ID_Ressource = msg_nodata Then
120+ Translation := 'Aucune donnée trouvée!'
121+ Else If ID_Ressource = msg_columnchooser Then
122+ Translation := 'Sélectionner les colonnes...'
123+ Else If ID_Ressource = msg_clearselection Then
124+ Translation := 'Annuler sélection'
125+ Else If ID_Ressource = msg_selectall Then
126+ Translation := 'Tout sélectionner'
127+ Else If ID_Ressource = msg_sortingasc Then
128+ Translation := 'Trier en mode croissant'
129+ Else If ID_Ressource = msg_sortingdesc Then
130+ Translation := 'Trier en mode décroissant';
131+End;
132+‎
133+```
134+
135+List of ressourcestring used by the TdxDBGridController
136+
137+- msg_search = 'Search...';
138+- msg_first = 'First';
139+- msg_prior = 'Prior';
140+- msg_next = 'Next';
141+- msg_last = 'Last';
142+- msg_add = 'Add';
143+- msg_delete = 'Delete';
144+- msg_edit = 'Edit';
145+- msg_save = 'Save';
146+- msg_cancel = 'Cancel';
147+- msg_refresh = 'Refresh';
148+- msg_btncancel = 'Cancel';
149+- msg_btnok = 'OK';
150+- msg_of = 'of';
151+- msg_nodata = 'No Data Found!';
152+- msg_columnchooser = 'Column Chooser...';
153+- msg_clearselection = 'Clear Selection';
154+- msg_selectall = 'Select All';
155+- msg_sortingasc = 'Sort by ascending order';
156+- msg_sortingdesc = 'Sort by descending order';
157+
158+## Screenshots
159+
160+### Global search
161+
162+![](/wiki-images/7/75/TdxDBGridController_SearchGrid.png)
163+
164+### Multi sort
165+
166+A Ctrl+Left clic is use to performe a multi column sorting, the index will appear under the sort indicator.
167+
168+![](/wiki-images/1/13/TdxDBGridController_MultiSort.png)
169+
170+### Column filter
171+
172+Once 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.
173+
174+![](/wiki-images/1/1b/TdxDBGridController_ColumnFilter.png)
175+
176+### Column search and aggregation
177+
178+It 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.
179+
180+![](/wiki-images/c/cc/TdxDBGridController_SearchAndAggregation.png)
181+
182+### TdxDBGridController properties
183+
184+![](/wiki-images/6/6c/TdxDBGridController_Properties.png)
185+
186+# See also
187+
188+- [[doc:lcl/dbgrids/tdbgrid.html|TDBGrid doc]]
189+- [[TDBGrid]]
190+- [[TStringGrid]]
191+- [[Grids Reference Page]]
192+
193+---
194+*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