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)
dynamic formatting
android272
<p>Is it possible to dynamically format my report at run-time? I need to be able to set a style of a cell based upon what column and the value of the cell. So if a cells value is above 23 and it is in "column_3" .setStyleName("customStyle");. </p>
<pre class="_prettyXprint _linenums:5">
// table detail
RowHandle tabledetail = (RowHandle) table.getDetail().get(0);
for (int i = 0; i < cols.size(); i++) {
CellHandle cell = (CellHandle) tabledetail.getCells().get(i);
DataItemHandle data = designFactory.newDataItem("data_" + cols.get(i));
data.setResultSetColumn(cols.get(i));
cell.getContent().add(data);
Map<String, String> map = highlight.get(i);
Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
System.out.println(pair.getKey() + " = " + pair.getValue());
System.out.println("cell = " + cell);
if (cell.getContent().equals(pair.getValue())) {
cell.setStyleName("customStyle");
}
}
}
</pre>
<p>originally I only had cell.setStyleName("LabelHeader"); with out all the complex loops around it and this colored every cell in my. Later I tried the code bellow and this colored ever other column.</p>
<pre class="_prettyXprint">
if (i % 2 == 0) {
cell.setStyleName("customStyle");
}
</pre>
<p>I thought this was weird because the variable "cell" is a CellHandle and not a ColumnHandle.</p>
<p> </p>
<p>Sorry if I am missing any needed information I don't know what will be helpful. Is there a way to do this in java? Is there a better way to do this? perhaps with a script or CSS? I don't want anything to do with the report designer.</p>
Find more posts tagged with
Comments
JFreeman
<p>The idea of iterating through each cell in every column and applying styles conditionally should work. There must be something within your logic that is causing it to always apply the same style.</p>
<p> </p>
<p>Regarding your second attempt, my guess is this is related to your original issue as well. Something in your logic is causing every cell to test true to your logic which is causing it to always apply the same styling. Because you added the modulus if statement, every other column will return false so instead of having the style applied to all cells in all columns you are now getting all cells in every other column.</p>
android272
<p>So I went back to my second attempt to figure out what happened. I changed the if(i%2==0) to if(i==3) to see what this would do. This changed everything in the fourth column(my <span style="color:rgb(0,0,0);font-family:monospace;font-size:13px;background-color:rgb(250,250,250);">cols</span><span style="color:rgb(102,102,0);font-family:monospace;font-size:13px;background-color:rgb(250,250,250);">.</span><span style="color:rgb(0,0,0);font-family:monospace;font-size:13px;background-color:rgb(250,250,250);">size</span><span style="color:rgb(102,102,0);font-family:monospace;font-size:13px;background-color:rgb(250,250,250);">()</span> is zero based so that's why 3 changed the fourth row).</p>
<p> </p>
<p>Also it looks as though it only iterates through the columns once and some how fills in all the data. Dose birt perform magic with SQL to just fill in all the data?</p>
android272
<p>So I guess this can only be achieved through scripting? I have not found anything that alludes to the ability to do this in java. perhaps I have to reconstruct this whole loop. I was thinking maybe looping down all the rows and then have an inner loop that iterates over the columns. But I still don't know how to get the cell data or add a style to it.</p>
android272
<p>I just confirmed on stack overflow that what I am trying to do here can not be done: <a data-ipb='nomediaparse' href='
http://stackoverflow.com/questions/30900838/birt-dynamic-formatting-of-cells'>http://stackoverflow.com/questions/30900838/birt-dynamic-formatting-of-cells</a></p>
;
<p> </p>
<p>So I need to <span style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:15px;">either </span><span style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:15px;">event handler or </span><a data-ipb='nomediaparse' href='
http://help.eclipse.org/luna/index.jsp?topic=/org.eclipse.birt.doc/birt/fm-HowToCreateAFormattingRule.html'>dynamic
formatting</a> or run a javascript. I sounds like the javascript will be the essayist... now I have to figure out how to make birt use javascript.</p>