TDBGridControler

From Free Pascal wiki
Revision as of 15:26, 30 December 2022 by Five (talk | contribs) (Five changed the content model of the page TDBGridControler from "wikitext" to "JavaScript")
Jump to navigationJump to search
== TDBGridController is a non visual component with no dependencies providing added functionalities for the TDBGrid object==



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


[[File:TdxDBGridControler_200.png|32px||Left|]] TDBGridController 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



{| class="wikitable"
|+ TDBGridController 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

<syntaxhighlight lang="pascal">
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;
</syntaxhighlight>


; Localization example, french translation of some of the component string resources

<syntaxhighlight lang="pascal">
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; 
</syntaxhighlight>


; Screen shots

[[File:TdxDBGridControler_SearchGrid.png]]


[[File:TdxDBGridControler_MultiSort.png]]


[[File:TdxDBGridControler_Properties.png]]

== See also ==

* [[doc:lcl/dbgrids/tdbgrid.html|TDBGrid doc]]
* [[TDBGrid]]
* [[TStringGrid]]
* [[Grids Reference Page]]