Skip to main content



      Home
Home » Archived » BIRT » How to format dates, times, etc. in script?
How to format dates, times, etc. in script? [message #54669] Thu, 07 July 2005 02:50 Go to next message
Eclipse UserFriend
Originally posted by: none.none.none

Hello,
The numeric and date formatting functions provided in the BIRT designer are
great. However, I often find myself needing to add a little text before or
after a value... for example...
"Total: " + Total.sum(row["col1"]);

How would I use the same formatting options here that are available via the
data element in the report designer? Javascript doesn't seem to have
functions to support this very easily.

Any ideas?
Thanks!
Re: How to format dates, times, etc. in script? [message #55045 is a reply to message #54669] Thu, 07 July 2005 20:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.none.none

Am I the only one doing this? Anyway, through the source code, I've tracked
down the BIRT way of doing things, so here's my solution for now....

------------------------------------------------------------ -------------------------
var formatter = new
Packages.org.eclipse.birt.core.format.NumberFormatter("$#,##0.00 ");

var val = row["col1"];

if (val != null)

{

"Total: " + formatter.format(val)

}

------------------------------------------------------------ -------------------------
The only other way I see is to use a grid with two cells... one cell for the
"Total:" label and the other cell for a data element for the numeric value
and apply a numeric formatting style to it. That is extremely cumbersome
and nearly impossible to get correct layout I want (spacing issues, etc.).

It would be nice to wrap this in static Javascript functions.... not sure
how or if I can do that (or if has already been done, but I couldn't find
anything on it).


"chris" <none@none.none> wrote in message
news:daijc2$h42$1@news.eclipse.org...
> Hello,
> The numeric and date formatting functions provided in the BIRT designer
> are great. However, I often find myself needing to add a little text
> before or after a value... for example...
> "Total: " + Total.sum(row["col1"]);
>
> How would I use the same formatting options here that are available via
> the data element in the report designer? Javascript doesn't seem to have
> functions to support this very easily.
>
> Any ideas?
> Thanks!
>
Re: How to format dates, times, etc. in script? [message #55100 is a reply to message #55045] Fri, 08 July 2005 02:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.none.none

Again, answered my own question. As for "wrapping" it into a javascript
function, it's quite simple...
Select the Page menu, then Code. In the oncreate event, you can add
something like this...

function formatNumber(val, pattern)
{
if (val != null)
{
var formatter = new
Packages.org.eclipse.birt.core.format.NumberFormatter(patter n);
return formatter.format(val);
}
else
{
return null;
}
}
.... and you will be able to acces that function globally. It took me a
little time to figure that out because I think the documentation is a little
misleading (or more likely, I'm probably misreading). Anyway, when trying
to figure out where to put global functions, this is all the info I get out
of the doc... "Non-local variables and all script functions, regardless of
where they are defined, are global in scope.". Yet, when I was adding this
into the "initialize" event of the report, it was not being found when
called. Anyway, that's a tangent. This seems to be working for me now,
but I get a feeling that my overall approach to this stuff is way off
track... but it's hard to know that when I'm fumbling through it all on my
own. But I'm finding BIRT is very powerful and very flexible, once you
learn how to flex its muscle.





"chris" <none@none.none> wrote in message
news:dakglq$1ah$1@news.eclipse.org...
> Am I the only one doing this? Anyway, through the source code, I've
> tracked down the BIRT way of doing things, so here's my solution for
> now....
>
> ------------------------------------------------------------ -------------------------
> var formatter = new
> Packages.org.eclipse.birt.core.format.NumberFormatter("$#,##0.00 ");
>
> var val = row["col1"];
>
> if (val != null)
>
> {
>
> "Total: " + formatter.format(val)
>
> }
Re: How to format dates, times, etc. in script? [message #55127 is a reply to message #55100] Fri, 08 July 2005 02:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.none.none

Correction... I thought the "Page" menu was a reference to some sort of high
level element. As it turns out, it simply changes your current view to
Code, etc. Meaning that I was putting that function in the code block of
whatever element was selected. While this still works (it seems to make it
global in scope anyway as the documentation states), I don't want to tie my
global function to a particular element that may or may not be deleted at a
later time. So where's a good place to put this stuff? As I mentioned
before, puting it in any of the Report element events doesn't seem to work.

"chris" <none@none.none> wrote in message
news:dal5nj$jl9$1@news.eclipse.org...
> Again, answered my own question. As for "wrapping" it into a javascript
> function, it's quite simple...
> Select the Page menu, then Code. In the oncreate event, you can add
> something like this...
>
> function formatNumber(val, pattern)
> {
> if (val != null)
> {
> var formatter = new
> Packages.org.eclipse.birt.core.format.NumberFormatter(patter n);
> return formatter.format(val);
> }
> else
> {
> return null;
> }
> }
> ... and you will be able to acces that function globally. It took me a
> little time to figure that out because I think the documentation is a
> little misleading (or more likely, I'm probably misreading). Anyway, when
> trying to figure out where to put global functions, this is all the info I
> get out of the doc... "Non-local variables and all script functions,
> regardless of where they are defined, are global in scope.". Yet, when I
> was adding this into the "initialize" event of the report, it was not
> being found when called. Anyway, that's a tangent. This seems to be
> working for me now, but I get a feeling that my overall approach to this
> stuff is way off track... but it's hard to know that when I'm fumbling
> through it all on my own. But I'm finding BIRT is very powerful and very
> flexible, once you learn how to flex its muscle.
Re: How to format dates, times, etc. in script? [message #56142 is a reply to message #55127] Mon, 11 July 2005 14:57 Go to previous messageGo to next message
Eclipse UserFriend
Here's an alternative:
Use a text element and set it to HTML/Dynamic type. Then, enter text, such
as the following, to combine literal text with a formatted field value:

Total: <value-of format=$#.00>Total.sum(row["col"])</value-of>

"chris" <none@none.none> wrote in message
news:dal6b7$kbk$1@news.eclipse.org...
> Correction... I thought the "Page" menu was a reference to some sort of
high
> level element. As it turns out, it simply changes your current view to
> Code, etc. Meaning that I was putting that function in the code block of
> whatever element was selected. While this still works (it seems to make
it
> global in scope anyway as the documentation states), I don't want to tie
my
> global function to a particular element that may or may not be deleted at
a
> later time. So where's a good place to put this stuff? As I mentioned
> before, puting it in any of the Report element events doesn't seem to
work.
>
> "chris" <none@none.none> wrote in message
> news:dal5nj$jl9$1@news.eclipse.org...
> > Again, answered my own question. As for "wrapping" it into a javascript
> > function, it's quite simple...
> > Select the Page menu, then Code. In the oncreate event, you can add
> > something like this...
> >
> > function formatNumber(val, pattern)
> > {
> > if (val != null)
> > {
> > var formatter = new
> > Packages.org.eclipse.birt.core.format.NumberFormatter(patter n);
> > return formatter.format(val);
> > }
> > else
> > {
> > return null;
> > }
> > }
> > ... and you will be able to acces that function globally. It took me a
> > little time to figure that out because I think the documentation is a
> > little misleading (or more likely, I'm probably misreading). Anyway,
when
> > trying to figure out where to put global functions, this is all the info
I
> > get out of the doc... "Non-local variables and all script functions,
> > regardless of where they are defined, are global in scope.". Yet, when
I
> > was adding this into the "initialize" event of the report, it was not
> > being found when called. Anyway, that's a tangent. This seems to be
> > working for me now, but I get a feeling that my overall approach to this
> > stuff is way off track... but it's hard to know that when I'm fumbling
> > through it all on my own. But I'm finding BIRT is very powerful and
very
> > flexible, once you learn how to flex its muscle.
>
>
Re: How to format dates, times, etc. in script? [message #56166 is a reply to message #56142] Mon, 11 July 2005 15:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.none.none

Yes, that is exactly what I was looking for. I figured there had to be
something. I saw the value-of element, but somehow missed the 'format'
attribute in the documentation.

Thanks!!

"Diana Peh" <diana.peh@actuate.com> wrote in message
news:daufcq$rju$1@news.eclipse.org...
> Here's an alternative:
> Use a text element and set it to HTML/Dynamic type. Then, enter text, such
> as the following, to combine literal text with a formatted field value:
>
> Total: <value-of format=$#.00>Total.sum(row["col"])</value-of>
>
Re: How to format dates, times, etc. in script? [message #56225 is a reply to message #54669] Mon, 11 July 2005 15:23 Go to previous message
Eclipse UserFriend
Hi, Chris,

Can you submit a bugzilla entry for an enhancement?

For now, you may be able to directly use the formatting classes in
org.eclipse.birt.core.format package to do formatting work. Let us know
your experience!

Stanley Wang
BIRT Engine

chris wrote:
> Hello,
> The numeric and date formatting functions provided in the BIRT designer are
> great. However, I often find myself needing to add a little text before or
> after a value... for example...
> "Total: " + Total.sum(row["col1"]);
>
> How would I use the same formatting options here that are available via the
> data element in the report designer? Javascript doesn't seem to have
> functions to support this very easily.
>
> Any ideas?
> Thanks!
>
>
Previous Topic:Report Viewer Class loading issue
Next Topic:Site Numbers
Goto Forum:
  


Current Time: Thu May 08 18:30:48 EDT 2025

Powered by FUDForum. Page generated in 0.04488 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top