Jump to content
uniGUI Discussion Forums
DayTripper

UnimDBGrid DisplayFormat for numeric columns

Recommended Posts

Hi all,

 

Does anyone know is there a way to format numeric values on mobile DBGrid.

Normal uniDBGrid can do it in renderer function, what about mobile DBGrid?

 

Than you.

 

Best regards,

Simon

Share this post


Link to post
Share on other sites

Hi

I've found the same issue...

 

The quick way is write  the onGetText event for every field.

 

procedure TForm1.numberFieldGetText(Sender: TField; var Text: string; DisplayText: Boolean);
begin
    text := formatFloat( TNumericField( sender ).DisplayFormat , sender.value );
end;

 

 

But if you have uniDBUtils.pas and you feel brave, you can touch the "numbers" section in the FieldValueToJS function:

    ...

    ftCurrency:
      begin
        if f.InheritsFrom( TNumericField ) and (TNumericField( f ).DisplayFormat<>'') then
            try
                result := '"'+formatFloat( TNumericField( f ).DisplayFormat , f.value )+'"';
            except
                Result := F.Value;
                // important: here we must use Delphi's {FormatSettings}.DecimalSeparator, becuase "F.Value" internally uses it to convert value to string.
                Result:=UniStringReplace(Result, {$ifdef COMPILER_15_UP}SysUtils.FormatSettings.{$endif}DecimalSeparator, '.');
            end
        else begin
            Result := F.Value;
            // important: here we must use Delphi's {FormatSettings}.DecimalSeparator, becuase "F.Value" internally uses it to convert value to string.
            Result:=UniStringReplace(Result, {$ifdef COMPILER_15_UP}SysUtils.FormatSettings.{$endif}DecimalSeparator, '.');
        end;
      end;
 

Share this post


Link to post
Share on other sites

Hello,

 

But if you have uniDBUtils.pas and you feel brave, you can touch the "numbers" section in the FieldValueToJS function:

    ...

    ftCurrency:
      begin
        if f.InheritsFrom( TNumericField ) and (TNumericField( f ).DisplayFormat<>'') then
            try
                result := '"'+formatFloat( TNumericField( f ).DisplayFormat , f.value )+'"';
            except
                Result := F.Value;
                // important: here we must use Delphi's {FormatSettings}.DecimalSeparator, becuase "F.Value" internally uses it to convert value to string.
                Result:=UniStringReplace(Result, {$ifdef COMPILER_15_UP}SysUtils.FormatSettings.{$endif}DecimalSeparator, '.');
            end
        else begin
            Result := F.Value;
            // important: here we must use Delphi's {FormatSettings}.DecimalSeparator, becuase "F.Value" internally uses it to convert value to string.
            Result:=UniStringReplace(Result, {$ifdef COMPILER_15_UP}SysUtils.FormatSettings.{$endif}DecimalSeparator, '.');
        end;
      end;
 

 

Which editon are you using ?!

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

×