Home
Analytics
In BIRT how to view different master-pages with different parameter that user selected
Zsy Zang
<p>I'm really new to BIRT, right now, I need to solve a problem that I want users can decide which Master page they want to see. For example, if a user want to see the number of vehicles in this period, he can select a parameter in the parameter page, and then the corresponding master page will be displayed. How can I achieve that, can anyone help me?</p>
<p> </p>
<p> </p>
Find more posts tagged with
Comments
Zsy Zang
<p>Response will be greatly appreciated</p>
JFreeman
<p>You can use some script in the beforeFactory of the report design to change the master page based on a report parameter value.</p>
<p>For Example:</p>
<pre class="_prettyXprint _lang-js">
var status = params["OrderStatus"].value;
if(status == "Shipped"){
reportContext.getDesignHandle().findElement("MyTable").setProperty("masterPage", "MP1");
}else{
reportContext.getDesignHandle().findElement("MyTable").setProperty("masterPage", "MP2");
}
</pre>
<p>I have also attached a simple sample report with this code for reference.</p>
Zsy Zang
<p> Hello Jesse,</p>
<p> </p>
<p>Thank you very much for your reply. But, it doesn't work to me. I want to display different graphs and tables on one master-page when a user select different parameter. I attached my code yesterday, could you help me check if there is anything wrong with my code? In my report, I want to display “table" and "mytable" on masterpage "Graph1" when user select "Top 10 busiest routes" with parameter "Static", and display "table2" and "atl" on the same masterpage when user select "Top 10 busiest moments". Here is my code</p>
<p> </p>
<p> </p>
<p>I also attached the report file. So, maybe you could check if there is anything wrong with my report?</p>
<p> </p>
<p>Thank you for your time</p>
<pre class="_prettyXprint _lang-">
var status = params["Static"].value;
if(status == "Top 10 busiest routes"){
reportContext.getDesignHandle().findElement("mytable").setProperty("masterPage", "Graph1");
reportContext.getDesignHandle().findElement("table1").setProperty("masterPage", "Graph1");
reportContext.getDesignHandle().findElement("atl").setProperty("masterPage", "Graph2");
reportContext.getDesignHandle().findElement("table2").setProperty("masterPage", "Graph2");
}else{
reportContext.getDesignHandle().findElement("atl").setProperty("masterPage", "Graph1");
reportContext.getDesignHandle().findElement("table2").setProperty("masterPage", "Graph1");
reportContext.getDesignHandle().findElement("table1").setProperty("masterPage", "Graph2");
reportContext.getDesignHandle().findElement("mytable").setProperty("masterPage", "Graph2");
}
</pre>
Zsy Zang
<p>I really need your help</p>
Zsy Zang
<p>can anyone help me?</p>
JFreeman
<p>Sorry for the delay in my response.</p>
<p> </p>
<p>I'm not sure I am clear on exactly what you are trying to accomplish after looking at your report design.</p>
<p>It looks like the elements you are trying to show/hide are in the body of the report and I only see one master page.</p>
<p> </p>
<p>I think you may be better off setting the visibility expression for the charts/tables you are wanting to show/hide conditionally.</p>
Zsy Zang
<p>Thank you for your rely,</p>
<p> </p>
<p> </p>
<p>In fact, I want to change the order of graph displayment with different parameter.</p>
<p> </p>
<p>For example, when I select "Top 10 busiest routes" with parameter "static", the order of displayment should be the graph "The Top 10 busiest routes" and the table above that graph will be displayed on the master-page "Graph1", and the graph "The Top 10 busiest moments" and the table above that graph will be displayed on the master-page “Graph2".</p>
<p> </p>
<p>If the user select "Top 10 busiest moments" with parameter â€static", the order of displayment should be the graph "The Top 10 busiest moments" and the table above that graph will be displayed on the master-page “Graph1", and the graph "The Top 10 busiest routes" and the table above that graph will be displayed on the master-page"Graph2". I have resubmitted the report design, so maybe you could help me?</p>
<p> </p>
<p> </p>
<p>Response greatly appreciated</p>
JFreeman
<p>So you want both charts/tables to be displayed for both situations but you want to change the order they are displayed in depending on the parameter value?</p>
Zsy Zang
<p>Exactly, could you help me on that?</p>
<p> </p>
<p>Thank you again for your reply</p>
JFreeman
<p>I will see about creating you a sample.</p>
<p> </p>
<p>When you are asking about changing the master page for this, I'm not exactly clear on what you are wanting as far as the master page goes.</p>
<p> </p>
<p>Are the chart/tables going to be the report contents in the body of the report (rearranged depending on parameter selection) and you want to use a different master page header/footer for this content also depending on the parameter selection?</p>
Zsy Zang
<p>Yes exactly. Thank you again for your kindly reply</p>
JFreeman
<p>I was able to achieve this by copying, dropping and adding the copies of the elements in the beforeFactory of the report design and then setting the applicable master page:</p>
<pre class="_prettyXprint _lang-js">
var status = params["Static"].value;
var routeChart = reportContext.getDesignHandle().findElement("routesChart");
var routeTable = reportContext.getDesignHandle().findElement("routesTable");
var momentChart = reportContext.getDesignHandle().findElement("momentsChart");
var momentTable = reportContext.getDesignHandle().findElement("momentsTable");
var reportBody = reportContext.getReportRunnable().designHandle.getBody();
if(status == "Top 10 busiest routes"){
//Set desired master page
routeChart.setProperty("masterPage", "Routes");
routeTable.setProperty("masterPage", "Routes");
momentChart.setProperty("masterPage", "Routes");
momentTable.setProperty("masterPage", "Routes");
}
if(status == "Top 10 busiest moment"){
//Make a copy of exisitng charts/tables
var momentChart2 = momentChart.copy();
var momentTable2 = momentTable.copy();
var routeChart2 = routeChart.copy();
var routeTable2 = routeTable.copy();
//Drop existing charts/tables and then add the copies in the desired order
routeChart.drop();
routeTable.drop();
momentChart.drop();
momentTable.drop();
reportBody.add(momentChart2);
reportBody.add(momentTable2);
reportBody.add(routeChart2);
reportBody.add(routeTable2);
//Set desired master page
momentChart2.setProperty("masterPage", "Moments");
momentTable2.setProperty("masterPage", "Moments");
routeChart2.setProperty("masterPage", "Moments");
routeTable2.setProperty("masterPage", "Moments");
}
</pre>
<p>Take a look at the attached modified version of your report for reference.</p>
Zsy Zang
<p>Thanks very much, Jesse. I changed a little for the code, and it's perfect!!! I really appreciate for your kindly help and your patience to my poor English. Anyway, thank you </p>
JFreeman
<p>You're welcome.</p>
<p>I'm glad that did the trick and got it working how you want.</p>
<p> </p>
<p>Let us know if you have additional questions.</p>