Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
data set parameter binding from script
jkr
Hello,
I have a table bound to a data set with parameters
I want to define the binds to the parameters from a script, probably on the onPrepare event
The table's Data Set parameters are param_1 and param_2
Any help or any direction for the code I should use would be appreciated
Dimitris
Find more posts tagged with
Comments
johnw
Not sure why you would want to do this instead of just using an expression in the data set parameter binding, but the following script will get the parameter binding element, clear it out, and add a new parameter binding based on a static expression.
in the onPrepare method:
//get the name of the table element to find
var thisElement = this.name;
//find the table based on the name and get the property handle for the parameter bindings
var parameterHandle = reportContext.getDesignHandle().findElement(thisElement).getPropertyHandle(
Packages.org.eclipse.birt.report.model.api.TableHandle.PARAM_BINDINGS_PROP );
//in this example, we have 1 existing parameter binding. Go ahead and remove it.
parameterHandle.removeItem(0);
//create a new parameter binding using the structure factory
var newParamBinding = org.eclipse.birt.report.model.api.StructureFactory.createParamBinding();
newParamBinding.paramName = "param_1";
newParamBinding.expression = "1002"; //set to customer record 1002
//add the new binding to the table
parameterHandle.addItem(newParamBinding);
jkr
Thank you very much
I actually want to set the data set parameters on the fly
because I have a grid 15x7 that each cell contains a table.
Each of the above table will contain a different data binding parameter
according to the grid column and row number that the table belongs to.
Another question:
Can I access the column and row number of the grid cell that the table is in
For columns it seems possible for me
this.getParent().column
But for rows ?
thnx
jkr
If I put the above script to the onCreate event
would it work ?
johnw
<blockquote class='ipsBlockquote' data-author="'jkr'" data-cid="71668" data-time="1293052725" data-date="22 December 2010 - 02:18 PM"><p>
If I put the above script to the onCreate event<br />
would it work ?<br /></p></blockquote>
<br />
No, it won't work in the onCreate event. The report lifecycle in BIRT won't allow modifications of that type during the onCreate phase, only the onPrepare. I'm still a little confused. If you know your always going to have a 15x7 grid, and each cell contains a table, why do you need the scripting to set the data binding? Why can't you just have 15x7 tables, each with its own binding? Is there something in the requirements that states that they need to be dynamic?
jkr
<blockquote class='ipsBlockquote' data-author="'johnw'" data-cid="71674" data-time="1293055599" data-date="22 December 2010 - 03:06 PM"><p>
No, it won't work in the onCreate event. The report lifecycle in BIRT won't allow modifications of that type during the onCreate phase, only the onPrepare. I'm still a little confused. If you know your always going to have a 15x7 grid, and each cell contains a table, why do you need the scripting to set the data binding? Why can't you just have 15x7 tables, each with its own binding? Is there something in the requirements that states that they need to be dynamic?<br /></p></blockquote>
<br />
<br />
I find it more time-consuming to copy-paste 15x7 times a table and then change 15x7 times the two parameters' data bindings ....<br />
Maybe at the end the time I will have spent to do it with scripting will be the same ...
but this way I will have learned about scripting.<br />
<br />
So I can do the binding onPrepare but the problem now is that I try to get the column number of the cell that the table is in (so I can assign it to the Parameter data binding value) but I always get the 0 value ...<br />
<br />
I do it this way:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>var colnum = thisTable.getContainer().getPropertyHandle(
org.eclipse.birt.report.model.api.CellHandle.COLUMN_PROP );
[...]
newParamBinding2.expression =colnum;</pre>
johnw
Maybe this.getParent().column might work, since the parent element of the table should be the cell.
actuser9
<p>[color=rgb(40,40,40);font-family:'Source Sans Pro', sans-serif;]Any ideas as to how to create a data set parameter binding on a grid linked to a data set from a data object? Any inputs are appreciated.[/color]</p>