Jump to content

dbgrid Columns proposed increase DisplayFormat property


yxzzjg

Recommended Posts

  • 2 years later...
In VCL I used '000000' in the DisplayFormat to display integer codes in dbgrid always adding 0 to the left.

 

Ex:

When code was 20 then 000020 was displayed.

 

In uniDBGrid it does not behave the same way.

How can I make this integer formation in dbgrid?

Link to comment
Share on other sites

Hi,

 

 

In VCL I used '000000' in the DisplayFormat to display integer codes in dbgrid always adding 0 to the left.
 
Ex:
When code was 20 then 000020 was displayed.
 
In uniDBGrid it does not behave the same way.
How can I make this integer formation in dbgrid?

 

 

You can open a ticket in support portal

 

As a workaround you can try to use something like this I think:

function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts)
{
    // 0 - your integer field index
    columns[0].renderer = function(v) {
      return (v.toString().padStart(6, '0'))
    }
}
Link to comment
Share on other sites

  • 1 month later...
even if I insisted on having a simpler solution,

 

today you have to write this code for the field's OnGetText method
procedure TMainForm.DataSetMyFieldGetText(Sender: TField; var Text: string;  DisplayText: Boolean);
begin
  Text:=FormatFloat('000000',Sender.AsFloat);
end; 

But (if Farshad Mohajeri does not change his mind) his only works if you change the property in the column 

Column.ForceStringFormat =true
Good job everyone
Link to comment
Share on other sites

In fact, putting extra zeros on front of a number has no meaning!

how do you not understand the usefulness?

- in a vcl application it is possible to format a column.

- in some databases the CAP is integer but is displayed with the forward zeros

- in some cases you do not want to display zero ... but in its place a hyphen.

- if you want to format the number of digits after the decimal point

etc etc ...

 

 

http://jira.fmsoft.net/servicedesk/customer/portal/4/FSD-568

I disagree with the visual result ... it can cause the original format to be lost to the field.

I did a test ... always using the same code

 

procedure TMainForm.ClientDataSet1LengthcmGetText(Sender: TField; var Text: string;  DisplayText: Boolean);
begin
  Text:=FormatFloat('0.00',Sender.AsFloat);
end;

 

and the VCL and UniGui visualization is different... look at the image attached.

I believe that UniGui is a great library and is used to bring your work on the web, keeping the operation more similar.

Thanks and thanks again for your work.

post-2430-0-29846500-1535473062_thumb.jpg

OnGetTextDiff.zip

Link to comment
Share on other sites

  • Administrators

how do you not understand the usefulness?

- in a vcl application it is possible to format a column.

- in some databases the CAP is integer but is displayed with the forward zeros

- in some cases you do not want to display zero ... but in its place a hyphen.

- if you want to format the number of digits after the decimal point

etc etc ...

 

 

http://jira.fmsoft.net/servicedesk/customer/portal/4/FSD-568

I disagree with the visual result ... it can cause the original format to be lost to the field.

I did a test ... always using the same code

 

procedure TMainForm.ClientDataSet1LengthcmGetText(Sender: TField; var Text: string;  DisplayText: Boolean);
begin
  Text:=FormatFloat('0.00',Sender.AsFloat);
end;

 

and the VCL and UniGui visualization is different... look at the image attached.

I believe that UniGui is a great library and is used to bring your work on the web, keeping the operation more similar.

Thanks and thanks again for your work.

 

I think there is a misunderstanding here.

I'm talking about leading zeros not zeros after the number.

 

uniGUI supports trailing zeros. for example: 1,0000000

but not leading zeros: 000000001,0

Link to comment
Share on other sites

- in some databases the CAP is integer but is displayed with the forward zeros

CAP - ZIP Code, codice postale

es.Roma 00100

but in some databases the value is saved as an integer = 100

 

 

to get this, in case the field has a DisplayFormat or GetText
I created this function
function GetFieldUseDisplayFormat(Fld: TField): boolean;
begin
  Result := false;
  if (Fld=nil) then exit;
  if ( Assigned(Fld.OnGetText) )  then Result := true
  else if Fld is TDateField then Result := (Fld as TDateField).DisplayFormat <> ''
  else if Fld is TTimeField then Result := (Fld as TTimeField).DisplayFormat <> ''
  else if Fld is TDateTimeField then Result := (Fld as TDateTimeField).DisplayFormat <> ''
  else if Fld is TCurrencyField then Result := (Fld as TCurrencyField).DisplayFormat <> ''
  else if Fld is TFloatField then Result := (Fld as TFloatField).DisplayFormat <> ''
{$ifdef COMPILER_14_UP}
  else if Fld is TSingleField then Result := (Fld as TSingleField).DisplayFormat <> ''
{$endif}
{$ifdef COMPILER_11_UP}
  else if Fld is TExtendedField then  Result := (Fld as TExtendedField).DisplayFormat <> ''
{$endif}
  else if Fld is TBCDField then Result := (Fld as TBCDField).DisplayFormat <> ''
  else if Fld is TFMTBCDField then Result := (Fld as TFMTBCDField).DisplayFormat <> ''
  else if Fld is TNumericField then Result := (Fld as TNumericField).DisplayFormat <> ''
end;
I changed the line of the
function GetFieldFormat(ACol: TUniBaseDBGridColumn; Fld: TField; var IsString: Boolean; var FType: string; DefaultFloatFormat: string =''): string;
in the unit uniDBUtils
 
  Result := '';
  FType := '';
  IsString := True;
  if (ACol.ForceStringFormat) or GetFieldUseDisplayFormat(Fld)  then // <--------
  begin
    // it must be string
  end
  else if Fld is TDateField then
I changed the line of the
function TUniCustomDBGrid.GetCellData(const ColNo: Integer; var HasAttr: Boolean): TUniCellRecord;
in the unit uniDBGrid
 else
      begin
        if GetFieldUseDisplayFormat(AField)  then // <--------
        begin
          if RawData then
            rValue := StrToJS(AField.DisplayText)
          else
            S := StrToJS(AField.DisplayText);
        end

this variation created it every time I apply a version update.

Link to comment
Share on other sites

  • 4 weeks later...

Thank yoy very much for this code!

I think It's the way like works in a regular VCL Grid

 

On 8/28/2018 at 11:03 PM, gerardocrisci said:

CAP - ZIP Code, codice postale

es.Roma 00100

but in some databases the value is saved as an integer = 100

 

 

to get this, in case the field has a DisplayFormat or GetText
I created this function

function GetFieldUseDisplayFormat(Fld: TField): boolean;
begin
  Result := false;
  if (Fld=nil) then exit;
  if ( Assigned(Fld.OnGetText) )  then Result := true
  else if Fld is TDateField then Result := (Fld as TDateField).DisplayFormat <> ''
  else if Fld is TTimeField then Result := (Fld as TTimeField).DisplayFormat <> ''
  else if Fld is TDateTimeField then Result := (Fld as TDateTimeField).DisplayFormat <> ''
  else if Fld is TCurrencyField then Result := (Fld as TCurrencyField).DisplayFormat <> ''
  else if Fld is TFloatField then Result := (Fld as TFloatField).DisplayFormat <> ''
{$ifdef COMPILER_14_UP}
  else if Fld is TSingleField then Result := (Fld as TSingleField).DisplayFormat <> ''
{$endif}
{$ifdef COMPILER_11_UP}
  else if Fld is TExtendedField then  Result := (Fld as TExtendedField).DisplayFormat <> ''
{$endif}
  else if Fld is TBCDField then Result := (Fld as TBCDField).DisplayFormat <> ''
  else if Fld is TFMTBCDField then Result := (Fld as TFMTBCDField).DisplayFormat <> ''
  else if Fld is TNumericField then Result := (Fld as TNumericField).DisplayFormat <> ''
end;
I changed the line of the
function GetFieldFormat(ACol: TUniBaseDBGridColumn; Fld: TField; var IsString: Boolean; var FType: string; DefaultFloatFormat: string =''): string;
in the unit uniDBUtils
 

  Result := '';
  FType := '';
  IsString := True;
  if (ACol.ForceStringFormat) or GetFieldUseDisplayFormat(Fld)  then // <--------
  begin
    // it must be string
  end
  else if Fld is TDateField then
I changed the line of the
function TUniCustomDBGrid.GetCellData(const ColNo: Integer; var HasAttr: Boolean): TUniCellRecord;
in the unit uniDBGrid

 else
      begin
        if GetFieldUseDisplayFormat(AField)  then // <--------
        begin
          if RawData then
            rValue := StrToJS(AField.DisplayText)
          else
            S := StrToJS(AField.DisplayText);
        end

this variation created it every time I apply a version update.

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...