Hi,
We are using the velocity plugin to display a complicated dataset, all is working fine but would now like to format columns into the correct format eg. currency, percentage etc, it seems the #tablizer ignores the default report parameters?, is there anyway of doing this ?, suggestions greatly appreciated.
What version of VelocityReport are you running?
BTW, I just release a v1.4, you should check it out.
About defaultReportParameters, there’s only one format available, which is the ‘numberFormat’ property which will be used for all floats/doubles.
Just tried it and it’s working here.
But perhaps your question is how to have many formats, is that it?
In which case, I guess you will have to forget about the #tablizer macro, and build your own #foreach loop then formatting each field the way you want it, using $number.currency($field) $number.integer($field) and $number.format(formatString, $field)
Hope this helps,
ptalbot:
What version of VelocityReport are you running?
BTW, I just release a v1.4. , you should check it out.About defaultReportParameters, there’s only one format available, which is the ‘numberFormat’ property which will be used for all floats/doubles.
Just tried it and it’s working here.But perhaps your question is how to have many formats, is that it?
In which case, I guess you will have to forget about the #tablizer macro, and build your own #foreach loop then formatting each field the way you want it, using $number.currency($field) $number.integer($field) and $number.format(formatString, $field)Hope this helps,
Hi Patrick , thanks for the reply
So the numberFormat property should work for data displayed within the tablizer?
wvitpr:
So the numberFormat property should work for data displayed within the tablizer?
Yes, and it works here for me, but as I said there’s only one default, so if for example I set
plugins.VelocityReport.setDefaultReportParameters( {numberFormat: "#.00' $'" } );
the #tablizer will use this format for all doubles and floats (not for integer ids).
If it doesn’t work this way for you using VelocityReport v1.4, please create an issue on ServoyForge (with a sample if possible) and I’ll have a look.
But again, since there is only one default format, if you need some numbers formatted with currency, others with percentage, others with yet another format, then you will have to build your own #foreach loop and use the $number object’s methods to format each field separately.
Hi Patrick,
Thankyou for your help. I am now formating most numbers in the table, except for those that are already to 2 decimal places… eg…
using numberFormat: “$###,###,###.00” I would expect the following 1000.12 = $1,000.12 but 1000.12 returns. If the original number is 1000.123 for example I get $1,000.12 which is good… any ideas.?.
Weird. I’ll have a look.
Maybe the formatter doesn’t like 1000.12… But how about 1000.13 or 1000.11? Do they work? (just kidding)
I made a test, using the latest VelocityReport version (v1.4.1), and it works for me.
I create a simple sample DB “test_db”, with a table containing 2 columns, id (INT) and test (DOUBLE), named the table ‘vel’,
I loaded these values:
|1|1000.1 |
|2|1000.12 |
|3|1000.123|
and tried using this code:
var ds = databaseManager.getDataSetByQuery("test_db","SELECT * FROM vel",null,-1);
var contextObject = { ds: ds };
var template = "#tablizer($ds, 'c', true)";
plugins.VelocityReport.setDefaultReportParameters({numberFormat: "$###,###,###.00"});
application.output(plugins.VelocityReport.evaluateWithContext(template,contextObject));
And I go this result:
<table class="c">
<thead>
<tr>
<th>Id</th>
<th>Test</th>
</tr>
</thead>
<tbody>
<tr class="even">
<td class="RecordObject">1</td>
<td class="RecordObject">$1,000.10</td>
</tr>
<tr class="odd">
<td class="RecordObject">2</td>
<td class="RecordObject">$1,000.12</td>
</tr>
<tr class="even">
<td class="RecordObject">3</td>
<td class="RecordObject">$1,000.12</td>
</tr>
</tbody>
</table>
which I believe is correct.
So I don’t know what’s wrong in your case. What version of VelocityReport do you use? Maybe you could try with the latest version?
If this fails, could you try and create a sample solution reproducing this bug and create an issue on the ServoyForge project?
Thanks,