Jump to content
uniGUI Discussion Forums
yxzzjg

dbgrid Columns proposed increase DisplayFormat property

Recommended Posts

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?

Share this post


Link to post
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'))
    }
}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Extjs formatter doesn't support adding them.

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

 

It is best to align right numbers and add trailing zeros.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Extjs formatter doesn't support adding them.

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

 

It is best to align right numbers and add trailing zeros.

 

Strange that if you do the same on a TUniDBEdit it works perfectly.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×