Difference between revisions of "TDBGridControler"

From Lazarus wiki
Jump to navigationJump to search
Line 37: Line 37:
 
|-
 
|-
 
|OnAfterFilterGrid
 
|OnAfterFilterGrid
|After filter execution
+
|Event handler signaled after filter execution
 
|-
 
|-
 
|OnAfterSortColumn
 
|OnAfterSortColumn
|After a column is sorted
+
|Event handler signaled after sorting a column  
 
|-
 
|-
 
|OnAggregation
 
|OnAggregation
|Define which column is showing an aggregation
+
|Event handler to define which column is showing an aggregation
 
|-
 
|-
 
|OnBeforeSortColumn
 
|OnBeforeSortColumn
|Before a column is sorted
+
|Event handler signaled before sorting a column  
 
|-
 
|-
 
|OnLocalize
 
|OnLocalize
|Use to translate string resources
+
|Event handler signaled to translate string resources
 
|-
 
|-
 
|OnPrepareLookupDataset
 
|OnPrepareLookupDataset
|Use to prepare the lookup dataset
+
|Event handler signaled to prepare the lookup dataset if needed
 
|-
 
|-
 
|OnSortColumn
 
|OnSortColumn
|Custom sort event, could be use to change order by statement in the SQL query     
+
|Event handler signaled to change the [order by] statement in a SQL query if needed    
 
|}
 
|}
  

Revision as of 23:17, 28 December 2022

TDBGridControler is a non visual component with no dependencies providing added functionalities for the TDBGrid object

Package download link : https://gitlab.com/lazaruscomponent/dbgridcontroler


TdxDBGridController 200.png TDBGridControler component


You need more functionalities? A grid controller that provide 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


TDBGridControler events
OnAfterFilterGrid Event handler signaled after filter execution
OnAfterSortColumn Event handler signaled after sorting a column
OnAggregation Event handler to define which column is showing an aggregation
OnBeforeSortColumn Event handler signaled before sorting a column
OnLocalize Event handler signaled to translate string resources
OnPrepareLookupDataset Event handler signaled to prepare the lookup dataset if needed
OnSortColumn Event handler signaled to change the [order by] statement in a SQL query if needed


Aggregation example on 2 lines
Procedure TForm1.dxDBGridControler1Aggregation(Sender: TdxDBGridControler);
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 example, french translation of some of the component string resources
Procedure TForm1.dxDBGridControler1Localize(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; 


Screen shots

TdxDBGridController SearchGrid.png


TdxDBGridController MultiSort.png


TdxDBGridController Properties.png

See also