Page 1 of 1

PostPosted: Wed Aug 30, 2006 9:59 am
by njw
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

PostPosted: Wed Aug 30, 2006 12:58 pm
by shannah
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

PostPosted: Wed Aug 30, 2006 9:11 pm
by Aoirthoir
Does this just work in displaying numbers on a page, or does it also perchance work in a form?

PostPosted: Wed Aug 30, 2006 10:33 pm
by shannah
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

PostPosted: Thu Aug 31, 2006 1:52 pm
by njw
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

PostPosted: Thu Aug 31, 2006 8:55 pm
by shannah
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

PostPosted: Fri Sep 01, 2006 12:37 am
by njw
No problem Steve, it's not a show stopper. I should be doing other things also!

Neil