Home
Analytics
Dynamic column width in grid
bainer
I am new to BIRT and have been digging in the Exchange for a way to dynamically change the width of the two columns in my grid.
We used to use OPTIO reporting tool which gave us the ability to build layers and have trigger code to toggle if that layer/secion is visible.
Now in BIRT I need to build the grid and place all the elements in the grid, however I have two different types of grids that need to print in the same location of my PDF. We have two shipping return label options. The data set will determine which label is generated.
We use BIRT 2.5.2 within MyEclipse Designer.
Currently I am modifying the this.width property within the column onCreate, but I just read that there is no such property to set at the column level.
My grid currently has one row and two columns (elements in each column are rotated 90 degrees). Each column contains their own grid(s) to contain the specific format for that return label.
I set the first grid within each column to be inline but that didn't do what I wanted. I think I would need both grids to be in the same column for that to work (CAN THAT BE DONE??)
When I print the first column's return label it prints with the top of the label at the left most edge of the report where I want it. However, when I am printing the second return label type the left most edge of the label is about 1.17in from the left edge of the report (value in the report that I am trying to override at runtime). I found that if I set the width of the first column to 0in and the width of the second column to 2.3333333333335in (width of the return label being developed) the desired outcome is met.
I have attached my report design with the onCreate methods in the grdLabels grid.
Can you help me figure out how I can dyncamically change the width of the columns to be able to print one return label type on my report?
Thank you in advance.
John
Find more posts tagged with
Comments
johnw
I just posted an example on how to set a grids column width dynamically.
http://www.birt-exchange.org/org/forum/index.php/topic/23547-master-page-dynamic-column-width/page__pid__83302__st__0&#entry83302
Read that over and see if that will do what you need.
bainer
johnw,
Thank you so much for your help and so quickly!
I applied what you suggested. It appears I am getting an error with the "row[....]" command to compare data in the dataset. It that command not available in the onPrepare?
Script and error received below:
Grid grdReturnLabels:
+ There are errors evaluating script " var name = "grdReturnLabels"; var element = reportContext.getDesignHandle().findElement(name); var column_shop = element.getColumns().get(0); var column_slmr = element.getColumns().get(1); if (row["RETURN_LABEL_TYPE"]=="SLMR") {column_shop.setStringProperty("width","0in"); column_slmr.setStringProperty("width","2.3333333333333335in");} else {column_shop.setStringProperty("width","1.21875in"); column_slmr.setStringProperty("width","1.1145833333333333in");} ":
ReferenceError: "row" is not defined. (/report/body/list[
@id="
;301"]/detail/grid[
@id="
;1149"]/row[
@id="
;1152"]/cell[
@id="
;1153"]/grid[
@id="
;1249"]/method[
@name="
;onPrepare"]#1)
birt.core.JavascriptCommonError ( 1 time(s) )
detail : org.eclipse.birt.report.engine.api.EngineException: There are errors evaluating script " var name = "grdReturnLabels"; var element = reportContext.getDesignHandle().findElement(name); var column_shop = element.getColumns().get(0); var column_slmr = element.getColumns().get(1); if (row["RETURN_LABEL_TYPE"]=="SLMR") {column_shop.setStringProperty("width","0in"); column_slmr.setStringProperty("width","2.3333333333333335in");} else {column_shop.setStringProperty("width","1.21875in"); column_slmr.setStringProperty("width","1.1145833333333333in");} ":
ReferenceError: "row" is not defined. (/report/body/list[
@id="
;301"]/detail/grid[
@id="
;1149"]/row[
@id="
;1152"]/cell[
@id="
;1153"]/grid[
@id="
;1249"]/method[
@name="
;onPrepare"]#1)
at org.eclipse.birt.report.engine.executor.ExecutionContext.addException(ExecutionContext.java:1215)
at org.eclipse.birt.report.engine.api.impl.ScriptedDesignHandler.processOnPrepareScript(ScriptedDesignHandler.java:202)
at org.eclipse.birt.report.engine.api.impl.ScriptedDesignHandler.handleOnPrepare(ScriptedDesignHandler.java:109)
at org.eclipse.birt.report.engine.api.impl.ScriptedDesignVisitor.visitGrid(ScriptedDesignVisitor.java:280)
at org.eclipse.birt.report.model.api.DesignVisitorImpl$Forwarder.visitGrid(DesignVisitorImpl.java:1137)
at org.eclipse.birt.report.model.elements.GridItem.apply(GridItem.java:132)
at org.eclipse.birt.report.model.api.DesignVisitorImpl.apply(DesignVisitorImpl.java:126)
at org.eclipse.birt.report.engine.api.impl.ScriptedDesignVisitor.visitCell(ScriptedDesignVisitor.java:367)
at org.eclipse.birt.report.model.api.DesignVisitorImpl$Forwarder.visitCell(DesignVisitorImpl.java:1101)
at org.eclipse.birt.report.model.elements.Cell.apply(Cell.java:78)
at org.eclipse.birt.report.model.api.DesignVisitorImpl.apply(DesignVisitorImpl.java:126)
at org.eclipse.birt.report.engine.api.impl.ScriptedDesignVisitor.visitRow(ScriptedDesignVisitor.java:355)
at org.eclipse.birt.report.model.api.DesignVisitorImpl$Forwarder.visitRow(DesignVisitorImpl.java:1125)
at org.eclipse.birt.report.model.elements.TableRow.apply(TableRow.java:79)
at org.eclipse.birt.report.model.api.DesignVisitorImpl.apply(DesignVisitorImpl.java:126)
at org.eclipse.birt.report.engine.api.impl.ScriptedDesignVisitor.visitGrid(ScriptedDesignVisitor.java:293)
at org.eclipse.birt.report.model.api.DesignVisitorImpl$Forwarder.visitGrid(DesignVisitorImpl.java:1137)
at org.eclipse.birt.report.model.elements.GridItem.apply(GridItem.java:132)
at org.eclipse.birt.report.model.api.DesignVisitorImpl.apply(DesignVisitorImpl.java:126)
at org.eclipse.birt.report.engine.api.impl.ScriptedDesignVisitor.visitList(ScriptedDesignVisitor.java:203)
at org.eclipse.birt.report.model.api.DesignVisitorImpl$Forwarder.visitList(DesignVisitorImpl.java:1053)
at org.eclipse.birt.report.model.elements.ListItem.apply(ListItem.java:62)
at org.eclipse.birt.report.model.api.DesignVisitorImpl.apply(DesignVisitorImpl.java:126)
at org.eclipse.birt.report.engine.api.impl.ScriptedDesignVisitor.visitReportDesign(ScriptedDesignVisitor.java:106)
at org.eclipse.birt.report.model.api.DesignVisitorImpl$Forwarder.visitReportDesign(DesignVisitorImpl.java:1199)
at org.eclipse.birt.report.model.elements.ReportDesign.apply(ReportDesign.java:65)
at org.eclipse.birt.report.model.api.DesignVisitorImpl.apply(DesignVisitorImpl.java:126)
at org.eclipse.birt.report.engine.api.impl.EngineTask.prepareDesign(EngineTask.java:1647)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:96)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:75)
at org.eclipse.birt.report.service.ReportEngineService.runAndRenderReport(ReportEngineService.java:920)
at org.eclipse.birt.report.service.BirtViewerReportService.runAndRenderReport(BirtViewerReportService.java:973)
at org.eclipse.birt.report.service.actionhandler.BirtGetPageAllActionHandler.__execute(BirtGetPageAllActionHandler.java:131)
at org.eclipse.birt.report.service.actionhandler.AbstractBaseActionHandler.execute(AbstractBaseActionHandler.java:90)
at org.eclipse.birt.report.soapengine.processor.AbstractBaseDocumentProcessor.__executeAction(AbstractBaseDocumentProcessor.java:47)
at org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.executeAction(AbstractBaseComponentProcessor.java:143)
at org.eclipse.birt.report.soapengine.processor.BirtDocumentProcessor.handleGetPageAll(BirtDocumentProcessor.java:183)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.process(AbstractBaseComponentProcessor.java:112)
at org.eclipse.birt.report.soapengine.endpoint.BirtSoapBindingImpl.getUpdatedObjects(BirtSoapBindingImpl.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)
at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)
at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)
at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
at org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.doPost(BirtSoapMessageDispatcherServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.service(BirtSoapMessageDispatcherServlet.java:122)
at org.eclipse.equinox.http.registry.internal.ServletManager$ServletWrapper.service(ServletManager.java:180)
at org.eclipse.equinox.http.servlet.internal.ServletRegistration.handleRequest(ServletRegistration.java:90)
at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:111)
at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:59)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.eclipse.equinox.http.jetty.internal.HttpServerManager$InternalHttpServiceServlet.service(HttpServerManager.java:318)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:502)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:380)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:535)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:880)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:748)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:213)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:520)
Caused by: org.eclipse.birt.core.exception.CoreException: There are errors evaluating script " var name = "grdReturnLabels"; var element = reportContext.getDesignHandle().findElement(name); var column_shop = element.getColumns().get(0); var column_slmr = element.getColumns().get(1); if (row["RETURN_LABEL_TYPE"]=="SLMR") {column_shop.setStringProperty("width","0in"); column_slmr.setStringProperty("width","2.3333333333333335in");} else {column_shop.setStringProperty("width","1.21875in"); column_slmr.setStringProperty("width","1.1145833333333333in");} ":
ReferenceError: "row" is not defined. (/report/body/list[
@id="
;301"]/detail/grid[
@id="
;1149"]/row[
@id="
;1152"]/cell[
@id="
;1153"]/grid[
@id="
;1249"]/method[
@name="
;onPrepare"]#1)
at org.eclipse.birt.report.engine.javascript.JavascriptEngine.evaluate(JavascriptEngine.java:287)
at org.eclipse.birt.core.script.ScriptContext.evaluate(ScriptContext.java:152)
at org.eclipse.birt.report.engine.executor.ExecutionContext.evaluate(ExecutionContext.java:746)
at org.eclipse.birt.report.engine.executor.ExecutionContext.evaluate(ExecutionContext.java:726)
at org.eclipse.birt.report.engine.executor.ExecutionContext.evaluate(ExecutionContext.java:708)
at org.eclipse.birt.report.engine.api.impl.ScriptedDesignHandler.processOnPrepareScript(ScriptedDesignHandler.java:194)
... 78 more
Caused by: org.mozilla.javascript.EcmaError: ReferenceError: "row" is not defined. (/report/body/list[
@id="
;301"]/detail/grid[
@id="
;1149"]/row[
@id="
;1152"]/cell[
@id="
;1153"]/grid[
@id="
;1249"]/method[
@name="
;onPrepare"]#1)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3557)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3535)
at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3620)
at org.mozilla.javascript.ScriptRuntime.nameOrFunction(ScriptRuntime.java:1718)
at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1657)
at org.mozilla.javascript.gen.c196._c0(/report/body/list[
@id="
;301"]/detail/grid[
@id="
;1149"]/row[
@id="
;1152"]/cell[
@id="
;1153"]/grid[
@id="
;1249"]/method[
@name="
;onPrepare"]:1)
at org.mozilla.javascript.gen.c196.call(/report/body/list[
@id="
;301"]/detail/grid[
@id="
;1149"]/row[
@id="
;1152"]/cell[
@id="
;1153"]/grid[
@id="
;1249"]/method[
@name="
;onPrepare"])
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:401)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3003)
at org.mozilla.javascript.gen.c196.call(/report/body/list[
@id="
;301"]/detail/grid[
@id="
;1149"]/row[
@id="
;1152"]/cell[
@id="
;1153"]/grid[
@id="
;1249"]/method[
@name="
;onPrepare"])
at org.mozilla.javascript.gen.c196.exec(/report/body/list[
@id="
;301"]/detail/grid[
@id="
;1149"]/row[
@id="
;1152"]/cell[
@id="
;1153"]/grid[
@id="
;1249"]/method[
@name="
;onPrepare"])
at org.eclipse.birt.report.engine.javascript.JavascriptEngine.evaluate(JavascriptEngine.java:282)
... 83 more
johnw
No, the row[] object isn't created until the onCreate phase. onPrepare is before any data is fetched, and the script won't work at that point since the grid object will have already been created with its sizes. It will run, but you won't see the desired effect.
What you cab do to get around that is use a dataset populated parameter, and use the parameter extraction task to pull that data. Scott Rosenbaum wrote an excellent tutorial on using data driven parameters to get around this limitation at:
http://birtworld.blogspot.com/2008/04/data-driven-reports.html
.
We might need to do some other trickery to get around this. Let me know if this method works, if not, we will spin the wheels to come up with something different.
bainer
Can you point me to another example? The link you directed me to is no longer available.
johnw
Take the period off the end of the link.
http://birtworld.blogspot.com/2008/04/data-driven-reports.html
bainer
johnw, The tutorial you sent me was fabulous! I implemented it in my report. However, now I can loop through the data, but I need to print this report for each row of detail returned in the parameter list.
I was wondering if I can create a total separate report to capture this data and within the loop call the genReport function to build the report for that one detail record, continuing that process until I was done printing for all rows in the parameter list. I think that would be quite expensive though.
Here is an idea of what I am looking for. We have a SELECTION which consists of many INVOICES. Each invoice can have a different type of return label which is why we did that onPrepare code in the first place, so we could prepare the grid for the particular type of return label. However, I need to be able to switch between two different types of return labels as I traverse through the INVOICES in the SELECTION. Maybe I am missing something and I can generate a page of the report within the FOR loop of the onPrepare??
Thank you for your time and help in advance.
Take care,
John I Bain
bainer
John,
I have decided to create a separate report that only loops through my invoice headers. In each iteration of the loop in a Java Event Handler onPrepare I wrote from code on the forum I am calling an engine.createRunAndRenderTask(design) for a separate report that is the invoice report. I am passing the invoice number as a parameter.
Now in the invoice report I am doing the onPrepare event parameterized data lookup as you directed me earlier and I am finding out the return label type for this invoice.
When I run the report separately the report prints with the correct return label and I see the debug file get created which tells me the code is firing. However, when I run the report that loops through the headers and calls the invoice report for each header, the code in the invoice report that does the parameterized data lookup for the return label code does not fire.
Here is my question: Does the onPrepare event fire when you call a report through the engine.createRunAndRender process?
Thank you for your time.