My problem is to present change the formatting of numbers that are
presented in a datagrid.  My list of numbers are in a float format,
but I would like to show them in a "$,2f" format, e.g. like $2.31.
Being new to weblocks, I was unsure how to change the format in the
datagrid and the best that I could come up with was to use the url
presentation with :present-as keyword.  My solution was to have a line
in the defview  of something like:

(current-price :present-as (url :body #'money-type))

where money-type is a function defined as:

(defun money-type (user-input presentation field view widget data-obj
&rest args)
  (with-html (:a :href "") (str (format nil "$~,2f" user-input))))

What I have done is essentially abused the url type by making the url
part refer to nothing, and just using the extra field to do my
formatting of the string.

Is there a better way to perform formatting of number fields in a
datagrid?

If not, I was wondering whether it wouldn't make sense to have another
type of presentation form as something like  (value-format "~,2f")
where the 'value-format' code word would trigger the use of the
following lisp string to format the value given by that field.   The
particular line in the defview statement would then be:

(current-price :present-as (value-format "$,2f") )

  Furthermore, I think it would also be helpful if there was a
presentation function like 'html-function' which would allow you to
just give the :present-as line a function that would operate on the
class-object and generate html that would show up in the datagrid,
something like

(current-price :present-as (html-function #'my-formatting-function) )

where html-function would pass the class object to my-formatting-
function  which would generate some html that would be put in the cell
for that value.  my-formatting-function would take just the class-
object, for simplicity, and then be of the form:

(defun my-formatting-function (class-object)
  (with-html (str (format nil "$,2f" (current-price class-object))))

Such an html-function as a presentation would also allow me to solve
another problem where I want the table to hold an icon which is
dependent on one of the fields in the class-object, although not
necessarily the one for which the function is being called.

As I said, I can currently accomplish both of these objectives by just
abusing the url presentation routine, but it might be cleaner to have
separate functions for each.

If I haven't completely missed the boat about how things are done in
weblocks--and I would encourage whatever advice I can on this--I would
be willing to take a stab at writing both of the above.

-- 
You received this message because you are subscribed to the Google Groups 
"weblocks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/weblocks?hl=en.

Reply via email to