Home
Analytics
Modify grid content in onCreate event
francisco
Hello,<br />
<br />
I need to modify the content (not the design) of a grid from an onCreate java event handler, but I can only modify the content from the onPrepare event. This is the code. Any suggestions? Thanks!!!<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
ReportDesignHandle design = reportContext.getDesignHandle();
GridHandle gridHandle = (GridHandle) design.getElementByID(1326);
for (int i=0;i<12;i++){
for (int j=0;j<31;j++){
RowHandle row = (RowHandle) gridHandle.getRows().get(j+1);
CellHandle cell = (CellHandle) row.getCells().get(i+1);
SlotHandle slot;
try {
slot = cell.getContent();
} catch (Exception e) {
throw new RuntimeException("Error during adding content to cell", e);
}
DesignElementHandle deh = slot.get(0);
LabelHandle label = (LabelHandle) deh;
try {
label.setText(String.valueOf(ausencias[i][j]));
} catch (SemanticException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
</pre>
Find more posts tagged with
Comments
mwilliams
So, you want to access a grid, step through each cell, access the label in that cell and dynamically change its text to a value from an array that is populated from a dataSet? Is this correct?
francisco
Yes, exactly!<br />
<br />
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="105310" data-time="1340745237" data-date="26 June 2012 - 02:13 PM"><p>
So, you want to access a grid, step through each cell, access the label in that cell and dynamically change its text to a value from an array that is populated from a dataSet? Is this correct?<br /></p></blockquote>
mwilliams
What's your BIRT version? I'll take a look.
francisco
BIRT version 2.5.1<br />
<br />
Thanks!!!<br />
<br />
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="105359" data-time="1340831645" data-date="27 June 2012 - 02:14 PM"><p>
What's your BIRT version? I'll take a look.<br /></p></blockquote>
mwilliams
Try setting this line:<br />
<br />
label.setText(String.valueOf(ausencias
[j]));<br />
<br />
to something like this:<br />
<br />
labelText = "String.valueOf(ausencias[" + i.toString() + "][" + j.toString() + "])";<br />
label.setOnCreate("this.text = " + labelText);<br />
<br />
This whole thing can be moved to the beforeFactory, too. Let me know. This should be close, anyways.
francisco
It doesn't seem to work. I think it cannot be moved to the beforeFactory event because the dataSet is still empty.
Regards.
mwilliams
It shouldn't matter. You're setting the onCreate script for each label, so the array just has to be filled by the time the onCreate for the label runs. When I tested it, I had to put a hidden text box bound to the dataSet I needed to run to fill the array, prior to the grid.
Take a look at this example.
francisco
It works!!!
Thank you!
mwilliams
You're welcome! Let us know whenever you have questions!