Numeric display formats

A place for users and developers of the Xataface to discuss and receive support.

Postby njw » Wed Aug 30, 2006 9:59 am

I am entering and displaying some big numbers in some fields - 16000000 for instance. Is there an easy way to have that displayed on screen as 16,000,000?

Many thanks

Neil
njw
 
Posts: 280
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Wed Aug 30, 2006 12:58 pm

Hi Neil,

You can customize the display of any field using delegate classes by implementing a method of the following form:

function fieldname__display(&$record){}

for example, say we have a field named 'price', and we want to format it nicely, we would implement a method as follows:

Code: Select all

function price__display(&$record){
    return number_format($record->val('price'));
}



Above examples used the php number_format function (http://php.net/number_format) to format the number nicely using commas and decimals...

Hope this helps.

-Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby Aoirthoir » Wed Aug 30, 2006 9:11 pm

Does this just work in displaying numbers on a page, or does it also perchance work in a form?
Aoirthoir
 
Posts: 420
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Wed Aug 30, 2006 10:33 pm

Forms are a little more complicated because there is a two-way going on. If you alter the display in a text field, you must be able to parse the value back to something acceptable by the database. This can be achieved using a combination of the fieldname__pushValue() and fieldname__pullValue() methods, described in this how to: http://framework.weblite.ca/documentation/how-to/how-to-define-custom-serialization-for-fields

Hope this helps a little.

-Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby njw » Thu Aug 31, 2006 1:52 pm

Hi Steve

Tried that and it doesn't work. Could this be because my field is integer, not float? I've tried using floatval instead of val, but that doesn't appear to work either!

Thanks for your help

Neil
njw
 
Posts: 280
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Thu Aug 31, 2006 8:55 pm

Hi Neil,

I'm currently up to my knees in the entrails of Dataface so I can't check this bug out... but I'll take a look in the next few days to see why it's not working... it is supposed to work...

Best regards

Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby njw » Fri Sep 01, 2006 12:37 am

No problem Steve, it's not a show stopper. I should be doing other things also!

Neil
njw
 
Posts: 280
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 34 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved