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