Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Example - Sort Table based on parameter (BIRT)"
(New page: {{Backlink|Report Developer Examples (BIRT)}} This example is [https://bugs.eclipse.org/bugs/show_bug.cgi?id=193590 Bugzilla ID 193590]. If you would like to contribute an example see the...) |
(→Description) |
||
Line 37: | Line 37: | ||
importPackage(Packages.org.eclipse.birt.report.model.api); | importPackage(Packages.org.eclipse.birt.report.model.api); | ||
importPackage(Packages.org.eclipse.birt.report.model.api.elements); | importPackage(Packages.org.eclipse.birt.report.model.api.elements); | ||
− | + | ||
delm = reportContext.getReportRunnable().designHandle.getDesignHandle().findElement("mytable"); | delm = reportContext.getReportRunnable().designHandle.getDesignHandle().findElement("mytable"); | ||
sc = StructureFactory.createSortKey(); | sc = StructureFactory.createSortKey(); | ||
sc.setKey("row[\"CONTACTLASTNAME\"]"); | sc.setKey("row[\"CONTACTLASTNAME\"]"); | ||
sc.setDirection("asc"); | sc.setDirection("asc"); | ||
− | + | ||
ph = delm.getPropertyHandle(TableHandle.SORT_PROP); | ph = delm.getPropertyHandle(TableHandle.SORT_PROP); | ||
ph.addItem(sc); | ph.addItem(sc); | ||
− | This script will add a sort condition to a named table at runtime using the DE API. | + | This script will add a sort condition to a named table at runtime using the DE API. |
+ | |||
== Comments == | == Comments == | ||
Please enter comments below by selecting the edit icon to the right. | Please enter comments below by selecting the edit icon to the right. |
Revision as of 14:07, 20 June 2007
< To: Report Developer Examples (BIRT)
This example is Bugzilla ID 193590. If you would like to contribute an example see the example contribution guidelines.
Introduction
This illustrates linking a report parameter to a sort condition on a table.
BIRT Version Compatibility
This example was built and tested with BIRT 2.2 RC3.
Example Files
Description
BIRT provides sorting at many levels. This simple example sorts a table based on a parameter. First the sample database is used to get the following query:
Select * from customers
Next a parameter is added to the report named srt, which is a static combo box with possible values of
firstcol secondcol thirdcol
These represent which column in the table will be used as the sort key. Next drag the query to the report canvas, which will create the table element. Select the properties for the table and choose the sorting tab. Add a sort key with the following expression for the key.
if( params["srt"].value == "firstcol" ){ row["CUSTOMERNUMBER"]; } else if( params["srt"].value == "secondcol"){ row["CUSTOMERNAME"]; } else if( params["srt"].value == "thirdcol"){ row["CONTACTLASTNAME"]; }
Now when executed, selecting the proper column will sort the table based on the chosen value.
Additional this example has a script that is commented out in the beforeFactory eventhandler for report. This script is shown below:
importPackage(Packages.org.eclipse.birt.report.model.api); importPackage(Packages.org.eclipse.birt.report.model.api.elements); delm = reportContext.getReportRunnable().designHandle.getDesignHandle().findElement("mytable"); sc = StructureFactory.createSortKey(); sc.setKey("row[\"CONTACTLASTNAME\"]"); sc.setDirection("asc"); ph = delm.getPropertyHandle(TableHandle.SORT_PROP); ph.addItem(sc);
This script will add a sort condition to a named table at runtime using the DE API.
Comments
Please enter comments below by selecting the edit icon to the right. You will need a Bugzilla account to add comments.