On Feb 12, 8:26 pm, clojure <[email protected]> wrote: > 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
You probably want to define your own presentation then. > 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. Yeah, that's pretty horrible. ;) > 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") ) Yes, a `format-presentation' class would make sense. > 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. Also not a bad idea. You can accomplish something similar using `html- presentation' with a custom :reader definition for the field. > 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. Absolutely. > 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. No, you seem to have a pretty good idea of how things are supposed to work in Weblocks. Leslie -- 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.
