TdxDBGridController
About
TDBGridController is a non visual component with no dependencies providing added functionalities for the TDBGrid object.
Download: https://gitlab.com/lazaruscomponent/dbgridcontroller
Licenses: MPL 2.0, LGPL.
Features
You need more functionalities? A grid controller that provides extra features to your existing TDBGrid:
- Searching expression in the grid
- Searching expression in column
- Column filter editor
- Datetime editor, memo editor and lookup editor
- Saving the current filter view
- Multi column sorting
- Column chooser editor
- Column grouping visual separator on one level
- Footer and aggregation on columns
TDBGrid overidden events to achive the task
- OnCellDraw
- OnCellHint
- OnEditorEdit
- OnMouseClick
- OnTitleClick
- OnTitleDraw
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.
Overriden event of the dataset linked to the DBGrid
- OnFilterRecord
If an OnFilterRecord event is used by the dataset, it will be replaced by the builtin event of the controller, no inheritance is taken into account in this case.
OnAfterFilterGrid | Event handler triggered after filter execution |
OnAfterSortColumn | Event handler triggered after sorting a column |
OnAggregation | Event handler to define which column is showing an aggregation |
OnBeforeSortColumn | Event handler triggered before sorting a column |
OnLocalize | Event handler triggered to translate string resources |
OnPrepareLookupDataset | Event handler triggered to prepare the lookup dataset if needed |
OnSortColumn | Event handler triggered to change the [order by] statement in a SQL query if needed |
Examples
Aggregation example on 2 lines
Procedure TForm1.dxDBGridController1Aggregation(Sender: TdxDBGridController);
Begin
Sender.ColumnPropertyList.ColumnPropertyByName('ProjectManager').FooterAlignment := taRightJustify;
Sender.ColumnPropertyList.ColumnPropertyByName('ProjectManager').FooterDisplayText :=
'Count Distinct : ' + Sender.ColumnPropertyList.Aggregation(agDistinct, 'ProjectManager').AsString;
// Use the FooterPanel property to set the height : dxDBGridControler1.FooterPanel.Height := Self.DBGrid1.DefaultRowHeight * 2;
Sender.ColumnPropertyList.ColumnPropertyByName('OpeningDate').FooterAlignment := taCenter;
Sender.ColumnPropertyList.ColumnPropertyByName('OpeningDate').FooterDisplayText :=
'Min : ' + Sender.ColumnPropertyList.Aggregation(agMin, 'OpeningDate').AsString + Char(13) + Char(10) +
'Max : ' + Sender.ColumnPropertyList.Aggregation(agMax, 'OpeningDate').AsString;
End;
Localization
This is an example, French translation of some of the component string resources:
Procedure TForm1.dxDBGridController1Localize(Sender: TObject; Component: TComponent; ID_Ressource: String; Var Translation: String);
Begin
If ID_Ressource = msg_search Then
Translation := 'Recherche...'
Else If ID_Ressource = msg_first Then
Translation := 'Aller au début'
Else If ID_Ressource = msg_prior Then
Translation := 'Précédent'
Else If ID_Ressource = msg_next Then
Translation := 'Suivant'
Else If ID_Ressource = msg_last Then
Translation := 'Aller à la fin'
Else If ID_Ressource = msg_add Then
Translation := 'Ajouter'
Else If ID_Ressource = msg_delete Then
Translation := 'Détruire'
Else If ID_Ressource = msg_edit Then
Translation := 'Éditer'
Else If ID_Ressource = msg_save Then
Translation := 'Enregistrer'
Else If ID_Ressource = msg_cancel Then
Translation := 'Annuler'
Else If ID_Ressource = msg_refresh Then
Translation := 'Actualiser'
Else If ID_Ressource = msg_btncancel Then
Translation := 'Annuler'
Else If ID_Ressource = msg_of Then
Translation := 'de'
Else If ID_Ressource = msg_nodata Then
Translation := 'Aucune donnée trouvée!';
End;
List of ressourcestring used by the TDBGridController
- msg_search = 'Search';
- msg_first = 'First';
- msg_prior = 'Prior';
- msg_next = 'Next';
- msg_last = 'Last';
- msg_add = 'Add';
- msg_delete = 'Delete';
- msg_edit = 'Edit';
- msg_save = 'Save';
- msg_cancel = 'Cancel';
- msg_refresh = 'Refresh';
- msg_btncancel = 'Cancel';
- msg_btnok = 'OK';
- msg_of = 'of';
- msg_nodata = 'No Data Found!';
- msg_columnchooser = 'Column Chooser';
- msg_clearselection = 'Clear Selection';
- msg_selectall = 'Select All';
- msg_sortingasc = 'Sort by ascending order';
- msg_sortingdesc = 'Sort by descending order';
Screenshots
Global search
Multi sort
A Ctrl+Left clic is use to performe a multi column sorting, the index will appear under the sort indicator
Column filter
Once you have focused on the grid you can have access to the column filter with the default shortcut Ctrl+J, this shortcut could be changed with the ColumnFilterShortCut property