Forum > Lazarus Extra Components
RX Library RXDBGrid and TDateTime
(1/1)
andreaboc:
Hi,
I'm using RXDBGrid with ZEOSLib for a project to explore PostgreSQL database.
My Application is a very simple PostgreSQL query bulder, a lightweight alternative of PgAdmin.
In this application you can write SQL queryes and view the result in the RXDBGrid placed bottom of the SynEdit Editor, and if you want you can edit data.
The problem is for timestamp columns (TDateTime): RxDBGrid try to handle this type with Date Editor
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---FRxDbGridLookupComboEditor in accord with the function:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function TRxDBGrid.EditorByStyle(Style: TColumnButtonStyle): TWinControl;but data contains both date and time and the control show only date withoout the possibility to edit time.
There is a way to edit both date and time? If not, how can I contribute to RxDBGrid project to add some features?
Thank you all..
alexs75:
Now in the RxFPC library there is no component for editing the date/time field - therefore this is the behavior of the grid. If you have ideas on how to implement such a component - write. I just didn't need it yet.
PS
for PG see my alternative of PgAdmin
https://github.com/lalexs75/FBManager
night builds
http://w7site.ru/fpc/fbm/
andreaboc:
Hi alexs75,
I just tried the FBManager software and found it very complete and efficient.
Congratulations for your work!
As I expected, connecting FBManager with my DB, the problem on the timestamp field remains: when i try to edit data, the combo for the date appears automatically without the possibility to edit the time and inevitably the information on the time is cleared. For me, make timestamp editable is very important.
I think to proceed i this way: first of all, I will try to create a component to extend TRxDBGrid with an option for choose if DateTime must be edited with a Combo (Ex on OptionExtra dgeUseDateTimePicker), than i will try to write a TDateTimePicker component for timestamp with both date and time.
If you want, I will keep you informed about the work.
PS: There is also the DateTimeCtrls Package for example that have very useful components for DateTime editing.
Thank you.
alexs75:
DateTimeCtrls is not a very good time editor. I tend to lean more towards the look and feel of the standard editor. Or by analogy as in Google Chrome. I will think about this topic.
andreaboc:
For now, I have extended TRxDBGrid with TAsyRxDBGrid Class that overwrite the method:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---EditorByStyle(Style: TColumnButtonStyle): TWinControl;
here the code:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit AsyRxDBGrid; {$mode objfpc}{$H+} interface uses Classes, SysUtils, LResources, LCLType, LCLIntf, Forms, Controls, Buttons, Graphics, Dialogs, Grids, DBGrids, DB, PropertyStorage, LMessages, types, StdCtrls, Menus, LCLVersion, rxdbgrid; type { TAsyRxDBGrid } TAsyRxDBGrid = class(TRxDBGrid) private FTempText : string; FStringEditor: TStringCellEditor; protected procedure UpdateData; override; procedure SetEditText(ACol, ARow: Longint; const Value: string); override; public function EditorByStyle(Style: TColumnButtonStyle): TWinControl; override; constructor Create(aOwner: TComponent); override; published end; procedure Register; implementation procedure Register;begin {$I asyrxdbgrid_icon.lrs} RegisterComponents('Asystel',[TAsyRxDBGrid]);end; { TAsyRxDBGrid } procedure TAsyRxDBGrid.UpdateData;var edField: TField;begin edField := SelectedField; if (edField<>nil) and (edField.DataType = ftDateTime) and (self.DataSource.DataSet.State in [dsEdit, dsInsert]) then begin edField.AsDateTime := StrToDateTime(FTempText); end else inherited UpdateData;end; procedure TAsyRxDBGrid.SetEditText(ACol, ARow: Longint; const Value: string);begin inherited SetEditText(ACol, ARow, Value); FTempText:=Value;end; function TAsyRxDBGrid.EditorByStyle(Style: TColumnButtonStyle): TWinControl;var F: TField;begin if Style = cbsAuto then begin F := SelectedField; if Assigned(F) then begin if F.DataType in [ftDateTime] then begin Result := FStringEditor; // for test reason use String editor... exit; end; end; end; Result:=inherited EditorByStyle(Style);end; constructor TAsyRxDBGrid.Create(aOwner: TComponent);begin Inherited Create(aOwner); FStringEditor := TStringCellEditor.Create(nil); FStringEditor.name :='StringEditor'; FStringEditor.Text:=''; FStringEditor.Visible:=False; FStringEditor.Align:=alNone; FStringEditor.BorderStyle := bsNone;end; end.
In this way, TAsyRxDBGrid handle TDateTime with standard String editor and I can edit both Date and Time.
Navigation
[0] Message Index