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)
Scripting Problems
Lianite
Greetings,
I am trying to use the scripting API to set a style for specific elements based on an if test.
I have been told that reportContext.getDesignHandle().getElementByID(element's_ID) will work to grab the element by it's id which I should then be able to manipulate. However I have been unsuccessful in implementing the setDisplay() and setHeight functions.
Can anyone assist me with this?
Thank you,
Jordan Trulen
Find more posts tagged with
Comments
mwilliams
Hi Jordan,
What version of BIRT are you using again? I'll take a look.
Lianite
Currently we are using 2.5.0
Thank you.
mwilliams
Jordan,
What element are you trying to do setHeight on?
Lianite
The cell of a crosstab. I need to be able to change it from 0.2 inches to 100%.
mwilliams
Jordan,
Can you explain more about what you're trying to get your crosstab to look like? That may help me in helping you get what you're looking for.
Lianite
It is the same as the last question that I needed assistance with.<br />
<br />
<a class='bbc_url' href='
http://www.birt-exchange.org/forum/designing-birt-reports/17658-styles-applying-styles-based-sections.html#post56986'>http://www.birt-exchange.org/forum/designing-birt-reports/17658-styles-applying-styles-based-sections.html#post56986</a><br
/>
<br />
We have found that if in the styles, you change the Display element to No-Display in combination with the height being 100%, the row will disappear entirely which is what we have been striving for.<br />
<br />
Normally this wouldn't be a problem, however we need to have each row defaulted to 0.2 inches in order to line up correctly with a table outside of the crosstab.<br />
<br />
Hope this helps.<br />
<br />
Jordan Trulen
mwilliams
Jordan,
You should be able to do something like this in your crosstab script for each cell you want to not show:
function onCreateCell( cellInst, reportContext )
{
if (cellInst.getCellID() == 310 || cellInst.getCellID() == 308 || cellInst.getCellID() == 427){
cellInst.getStyle().setDisplay("none");
}
}
Doesn't look like the height of 100% needs to be set.
Lianite
What do you pass into the function as cellInst?
mwilliams
You have that code exactly as posted in your crosstab's onCreate script. The only things you'd change would be the cell ID's from the row you want to make "not display". I used the report we worked with in the other thread. You should be able to copy that code into the script for the crosstab in that report, view it in PDF, and see the results.
Lianite
Excellent! Thank you much.
mwilliams
No problem. Let me know if you have any questions.
Lianite
Got one more question for this problem.
How do I check the value of certain cells for particular values in the script for the crosstab?
Such as: getCellID(217).getValue() == 'etc' && getCellID(218).getValue() == 'misc'
Whenever I try, it does not want to work.
What would the syntax be for that?
mwilliams
Jordan,
You said in the other post that you know the ones that will need to be hidden for each Location. If this is the case you could modify your function to be something like:
function onCreateCell( cellInst, reportContext )
{
if (cellInst.getDataValue("LOCATION") == "AAA"){
if (cellInst.getCellID() == 310 || cellInst.getCellID() == 308 || cellInst.getCellID() == 427){
cellInst.getStyle().setDisplay("none");
}
}
}
Then just include checks for all "locations" and list each cell you want to hide for each. Hopefully this helps in you situation. Let me know.
Lianite
Thanks.
It appears to be working correctly now.
mwilliams
Great! Let me know if you run into any other issues.
Lianite
Alright, I have been working on implementing this in our report, and it has succeeded in one aspect. I was able to remove the cells from the horizontal flow, but not from the vertical flow.
By that I mean that the lower cells will not shift up to fill in blank space when I remove the desired cells.
Any idea how to fix this? I still think that I need to set the height to 100%.
Thank you,
Jordan
mwilliams
Jordan,
setting the height to 100% should just take one more line of script. Let me know if it changes anything.
Lianite
I have tried cellInst.setHight("100%"), however an error is thrown that setHeight() is not a recognized function. I have also tried cellInst.getStyle().setHeight("100%"), however that throws the same error.<br />
<br />
What would the syntax be to call the function. I have not been able to figure out how to read the Script API yet, however I have found the function that I desire to use.<br />
<br />
Set height is in the following:<br />
<a class='bbc_url' href='
http://www.birt-exchange.org/documentation/BIRT_220/EngineJavadoc/enginescript/api/index.html'>Birt
Script API</a> ,<br />
org.eclipse.birt.report.engine.api.script.element,<br />
IReportItem,<br />
setHeight<br />
however I do not know how to call that particular method.<br />
<br />
Jordan
mwilliams
Jordan,
See if this helps. I don't know if I know what the problem is you're having, but this is one of the ways I found that a height property could be set with no errors. Could be the wrong thing though.
reportContext.getDesignHandle().getElementByID(cellInst.getCellID()).setStringProperty("height","100%");
Lianite
Unfortunately, that did not do what I was hoping it was going to do.
I have attached a screen shot of the output we are getting. All the blank lines should not be there, it should be line of text after line of text.
I change the display to none, change the height to 100%, and remove bottom borders, all padding and all margins to each of the rows that are blank.
Any ideas?
I should note that it is the 5-6 columns on the left. The 5 columns on the right are a table that is right next to the crosstab. I am only worrying about the crosstab at the moment as I know how to deal with the rows on the table.
mwilliams
Jordan,
If you can get this issue reproduced somehow, that'd be a great help for testing to see if I can figure anything out. I do know that a crosstab's structure is a lot harder to mess with than a table's, as you've seen.
Lianite
Unfortunately, I am not the creator, I am just doing the scripting for this. I will contact the creator to see if they can create a mock up using the Classic Cars DB.
In the meantime, I have discovered the only hitch to getting this to work correctly. I have tried running the report by manually setting a cell row to 100% height and then it worked correctly, so there is some kind of problem with the function that you gave me to make the cell height change from 0.2 inches to 100%.
Is there any other way to dynamically change the height of a cell?
Jordan
mwilliams
Jordan,
I'm looking into it still. I don't know if what I gave you was truly setting the height of the cell. I'll have to set the height and grab that same value to see if that is for sure the case. I'll let you know what I find.
Lianite
Thank you much Michael.
mwilliams
Unfortunately I haven't been able to figure out a way to set this in script. Can you log a bug for this at <a class='bbc_url' href='
http://www.eclipse.org/birt/phoenix/reportabug.php'>BIRT
: Reporting Bugs and Requesting Enhancements</a>. Be sure to describe what you're trying to find it for and possibly request for an enhancement for a better way to hide rows in a crosstab. Thanks.
Lianite
Thank you for looking into this for us Michael.
One of my co-workers had the idea to determine the height that we needed by changing the margins/padding to accommodate the extra space we needed instead of using the 0.2 inches height. By doing this, we were able to change the height to 100% for every cell, and thus am able to use the script that you had sent to me to remove the cells.
It is a bit of a roundabout way to accomplish the task, however it is all that is available currently apparently. There is an enhancement request out for improving the visibility options for cross-tabs already.
Again, thank you for all your time and effort to help us resolve our issue.
mwilliams
Jordan,
No problem at all! Let us know whenever you have questions!