Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
dynamically create the table from hashmap
suman45454
<p>Hi, I will be getting hashmap from java function.Whose key will be column name and value will be value of each key.And i want to order the same insertion order of hashmap to be displayed.</p>
<p>i want to dynamically create the table in Birt javaScript.Any suggestion plz</p>
Find more posts tagged with
Comments
Clement Wong
<p>This question should have been posted in the Designer BIRT Reports section, and I'll move after I have replied.</p>
<p> </p>
<p> </p>
<p>So you'll want to use a Scripted Data Source / Scripted Data Set.</p>
<p> </p>
<p>In the <em>open </em>event of the Scripted Data Set, you'll want to initialize your variable for the hashmap iterator (entriesIterator).</p>
<pre class="_prettyXprint _lang-">
var myHashmap = new Packages.java.util.HashMap();
myHashmap.put("key1", "Value1");
myHashmap.put("key2", "Value2");
myHashmap.put("key3", "Value3");
myHashmap.put("key4", "Value4");
myHashmap.put("key5", "Value5");
//myHashmap.entrySet()
//[key1=Value1, key2=Value2, key5=Value5, key3=Value3, key4=Value4]
entriesIterator = myHashmap.entrySet().iterator();
</pre>
<p>Then, in the <em>fetch </em>event, you'll want to loop through the entries and get its key and value.</p>
<pre class="_prettyXprint _lang-">
if (entriesIterator.hasNext()) {
var e = entriesIterator.next()
row["key"] = e.getKey();
row["value"] = e.getValue();
return true;
}
else {
return false;
}
</pre>
<p>Attached is the sample report design (was created in OS BIRT 4.6.0).</p>