Column Sorting BIRT Dynamic Table Column Sorting
#1
Posted 18 June 2012 - 05:44 AM
I have a requirement, on which I have to work very urgently.
I have a Report. The report has a table. The table has 10 columns. The report has 3 input Report parameters,
based on which the report runs. I have provided the implementation so far. I am using the Scripted datasource
My requirement is, once the report is rendered, The user should be able to sort the report by clicking on the
table columns. So far, I have implemented the full report except the sorting functionality.
Can any one please tell me how to implement the dynamic sorting functionality in BIRT Report tables..?
Thanks in advance....
--Sunil
#2
Posted 18 June 2012 - 01:47 PM
#3
Posted 20 June 2012 - 04:27 AM
How to give label value to report parameter?
I can give my rptdesign file here.
This report takes 'project' as input, then runs the report.
It has 2 report parameters(project, sortkey(hidden, here is where I want the column label to come))
I am using scripted datasource.
<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.21" id="1">
<property name="comments">Copyright © 2011 Vue Technology</property>
<property name="createdBy">Eclipse BIRT Designer Version 2.6.0.v20100531 Build <2.6.0.v20100609-1613></property>
<html-property name="description">Emp Report</html-property>
<simple-property-list name="includeResource">
<value>resources</value>
</simple-property-list>
<property name="units">in</property>
<property name="theme">vue_library.defaultTheme</property>
<text-property name="displayName">Emp Report</text-property>
<property name="iconFile">/templates/blank_report.gif</property>
<property name="layoutPreference">auto layout</property>
<list-property name="libraries">
<structure>
<property name="fileName">vue_library.rptlibrary</property>
<property name="namespace">vue_library</property>
</structure>
</list-property>
<parameters>
<scalar-parameter name="project" id="1215">
<text-property name="promptText">Enter Project</text-property>
<property name="valueType">static</property>
<property name="dataType">string</property>
<property name="distinct">true</property>
<property name="paramType">simple</property>
<property name="controlType">text-box</property>
<structure name="format">
<property name="category">Unformatted</property>
</structure>
</scalar-parameter>
<scalar-parameter name="sortkey" id="1217">
<property name="hidden">true</property>
<property name="valueType">static</property>
<property name="isRequired">false</property>
<property name="dataType">string</property>
<property name="distinct">true</property>
<property name="paramType">simple</property>
<property name="controlType">text-box</property>
<structure name="format">
<property name="category">Unformatted</property>
</structure>
</scalar-parameter>
</parameters>
<data-sources>
<script-data-source name="Data Source" id="1210"/>
</data-sources>
<data-sets>
<script-data-set name="Data Set" id="1211">
<list-property name="resultSetHints">
<structure>
<property name="position">0</property>
<property name="name">id</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">1</property>
<property name="name">name</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">project</property>
<property name="dataType">string</property>
</structure>
</list-property>
<list-property name="columnHints">
<structure>
<property name="columnName">id</property>
</structure>
<structure>
<property name="columnName">name</property>
</structure>
<structure>
<property name="columnName">project</property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">id</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">name</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">3</property>
<property name="name">project</property>
<property name="dataType">string</property>
</structure>
</list-property>
</structure>
<property name="dataSource">Data Source</property>
<method name="open"><![CDATA[readerClass = new Packages.com.tyco.trafint.data.EmpDataSource();
data = readerClass.getReportData(params["project"].value);
totalrows = data.size();
currentrow = 0;]]></method>
<method name="fetch"><![CDATA[if( currentrow >= totalrows )
{
return( false );
}
var dataRow = data.get(currentrow);
row["id"]=dataRow[0];
row["name"]=dataRow[1];
row["project"]=dataRow[2];
currentrow = currentrow + 1;
return ( true );]]></method>
</script-data-set>
</data-sets>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<property name="orientation">landscape</property>
<property name="topMargin">0.5in</property>
<property name="leftMargin">0.5in</property>
<property name="bottomMargin">0.5in</property>
<property name="rightMargin">0.3in</property>
<property name="headerHeight">0in</property>
<property name="footerHeight">0in</property>
</simple-master-page>
</page-setup>
<body>
<table name="reportTable" id="8">
<list-property name="userProperties">
<structure>
<property name="name">ShowChartsOnlyOnFirstPage</property>
<property name="type">string</property>
</structure>
<structure>
<property name="name">DrillDownReports</property>
<property name="type">string</property>
</structure>
<structure>
<property name="name">ReportTableHeaderRowIndex</property>
<property name="type">integer</property>
</structure>
</list-property>
<property name="width">100%</property>
<property name="dataSet">Data Set</property>
<list-property name="boundDataColumns">
<structure>
<property name="name">id</property>
<expression name="expression" type="javascript">dataSetRow["id"]</expression>
<property name="dataType">string</property>
</structure>
<structure>
<property name="name">name</property>
<expression name="expression" type="javascript">dataSetRow["name"]</expression>
<property name="dataType">string</property>
</structure>
<structure>
<property name="name">project</property>
<expression name="expression" type="javascript">dataSetRow["project"]</expression>
<property name="dataType">string</property>
</structure>
</list-property>
<property name="pageBreakInterval">50</property>
<column id="1136">
<property name="width">33%</property>
</column>
<column id="1155">
<property name="width">33%</property>
</column>
<column id="1184">
<property name="width">34%</property>
</column>
<header>
<row id="145">
<cell id="146">
<property name="colSpan">3</property>
<property name="rowSpan">1</property>
<grid id="151">
<property name="width">100%</property>
<column id="152"/>
<column id="153"/>
<row id="154">
<cell id="155">
<text id="1209">
<property name="fontFamily">"Arial"</property>
<property name="fontSize">12pt</property>
<property name="fontWeight">bold</property>
<property name="color">#800000</property>
<property name="contentType">html</property>
<text-property name="content"><![CDATA[<center>This report is used to test Column Sorting in BIRT</center>
<BR>]]></text-property>
</text>
</cell>
<cell id="157"/>
</row>
</grid>
</cell>
</row>
<row id="1205">
<property name="repeatable">false</property>
<cell id="1206">
<property name="colSpan">3</property>
<property name="rowSpan">1</property>
<property name="paddingTop">1pt</property>
<property name="paddingLeft">1pt</property>
<property name="paddingBottom">1pt</property>
<property name="paddingRight">1pt</property>
<property name="textAlign">center</property>
<text-data id="1216">
<property name="fontFamily">"Arial"</property>
<property name="color">#808080</property>
<expression name="valueExpr">"Search Results for: Project: "+params["project"].value</expression>
<property name="contentType">html</property>
</text-data>
</cell>
</row>
<row id="9">
<cell id="1133">
<property name="style">vue-table-header</property>
<label id="1185">
<text-property name="text">ID</text-property>
</label>
</cell>
<cell id="1152">
<property name="style">vue-table-header</property>
<label id="1186">
<text-property name="text">Name</text-property>
</label>
</cell>
<cell id="1181">
<property name="style">vue-table-header</property>
<label id="1187">
<text-property name="text">Project</text-property>
</label>
</cell>
</row>
</header>
<detail>
<row id="32">
<list-property name="highlightRules">
<structure>
<property name="operator">eq</property>
<property name="backgroundColor">#F5F5E8</property>
<expression name="testExpr">row["__rownum"]%2</expression>
<simple-property-list name="value1">
<value>0</value>
</simple-property-list>
</structure>
</list-property>
<cell id="1134">
<data id="1212">
<property name="whiteSpace">nowrap</property>
<property name="resultSetColumn">id</property>
</data>
</cell>
<cell id="1153">
<data id="1213">
<property name="whiteSpace">nowrap</property>
<property name="resultSetColumn">name</property>
</data>
</cell>
<cell id="1182">
<data id="1214">
<property name="whiteSpace">nowrap</property>
<property name="resultSetColumn">project</property>
</data>
</cell>
</row>
</detail>
<footer>
<row id="55">
<cell id="1135"/>
<cell id="1154"/>
<cell id="1183"/>
</row>
</footer>
</table>
</body>
</report>
Above is my report. I have 3 columns in my table. They are ID, Name, Project.
As you said to create a drill-through on the header label of the column, I can do the below code for that.
(This code is not there in the above report).
<cell id="14">
<label id="15">
<text-property name="text">ID</text-property>
<list-property name="action">
<structure>
<property name="linkType">drill-through</property>
<property name="reportName">employee.rptdesign</property>
<property name="targetWindow">_self</property>
<property name="targetFileType">report-design</property>
</structure>
</list-property>
</label>
</cell>
<cell id="14">
<label id="15">
<text-property name="text">Name</text-property>
<list-property name="action">
<structure>
<property name="linkType">drill-through</property>
<property name="reportName">employee.rptdesign</property>
<property name="targetWindow">_self</property>
<property name="targetFileType">report-design</property>
</structure>
</list-property>
</label>
</cell>
<cell id="14">
<label id="15">
<text-property name="text">Project</text-property>
<list-property name="action">
<structure>
<property name="linkType">drill-through</property>
<property name="reportName">employee.rptdesign</property>
<property name="targetWindow">_self</property>
<property name="targetFileType">report-design</property>
</structure>
</list-property>
</label>
</cell>
But how to write code to pass the column label to the report parameter?
Thanks in advance....
--Sunil
#4
Posted 20 June 2012 - 09:12 PM
Attached File(s)
-
DynamicSort.rptdesign (13.97K)
Number of downloads: 26
#5
Posted 20 June 2012 - 09:37 PM
My Report has input report parameter, based on which my report runs.
When I click on the column header, the report has to be re-run with sort key(column name).
I am using scripted datasource.
I have seen one example report on column sorting on the web. But that report is using JDBC datasource and it doesn't have any input report parameters. It has a plain SQL Query. Every time a click on the column label, that will be appended to the order by clause in the query. This example is not solving my problem.
In my requirement, every time there is a click on my column, there should be a way to pass the column label to the method, which I have defined in the data source class and also the report parameter to be passed.
Thanks in advance.
#6
Posted 20 June 2012 - 09:49 PM
#7
Posted 21 June 2012 - 04:16 AM
It worked fine when I run the report(click on column headers) in Eclipse BIRT Viewer.
But, It failed when I run(click on column headers) from JBoss 4.2.3 server.
I got the following error when I try to sort the columns(click on the column headers)
There is no report design object available.
org.eclipse.birt.report.exception.ViewerException: There is no report design object available.
at org.eclipse.birt.report.context.ViewerAttributeBean.__init(ViewerAttributeBean.java:226)
at org.eclipse.birt.report.context.BaseAttributeBean.init(BaseAttributeBean.java:233)
at org.eclipse.birt.report.context.ViewerAttributeBean.<init>(ViewerAttributeBean.java:118)
at org.eclipse.birt.report.context.BirtContext.__init(BirtContext.java:44)
at org.eclipse.birt.report.context.BaseContext.<init>(BaseContext.java:69)
at org.eclipse.birt.report.context.BirtContext.<init>(BirtContext.java:30)
at org.eclipse.birt.report.servlet.ViewerServlet.__getContext(ViewerServlet.java:150)
at org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.doGet(BirtSoapMessageDispatcherServlet.java:151)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.service(BirtSoapMessageDispatcherServlet.java:122)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.eclipse.birt.report.filter.ViewerFilter.doFilter(ViewerFilter.java:68)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:722)
#8
Posted 21 June 2012 - 11:36 AM
#9
Posted 21 June 2012 - 11:17 PM
In JBoss, it is still not working.
Thank you very much for your help.
This approach works in only single direction(ascending order).
Can you please tell me the approach on how to perform sort in both directions(ascending, descending)?
I mean, the sort direction should keep on changing for every click on the column header.
Thanks in advance.
#10
Posted 22 June 2012 - 07:19 AM
#11
Posted 27 June 2012 - 09:17 AM
Attached File(s)
-
DynamicSort.rptdesign (15.89K)
Number of downloads: 31






MultiQuote





