Tuesday, February 12, 2013

BIRT Sorting

BIRT provides sorting capabilities on many report items, including Tables, Lists, Cross Tabs, Charts and Groups.  Sorting is configured using a sort key expression.  The expression is usually tied to data that is returned in a BIRT data set.  In addition to supporting sort direction, BIRT also supports locale specific sorting and sort strength.

 The expression is entered at various locations in the designer and depends on what report item is being sorted.  For Cross Tabs, Lists and Tables the sorting expression can be entered in the property view, under the sorting tab.

The sorting expression for Charts is defined in the Select Data tab of the chart wizard, next to the expression for the category or optional grouping expression.

Group sorting is defined in the Group Editor.

If your BIRT report uses a grouped table, by default the group will be sorted by your key expression.  In some cases this may not be desirable.  Specifically when the data is pre-sorted in the order you want it to appear.  BIRT provides an advanced property to turn this behavior off.  You can access this property (“Sort by groups”) in the advanced table of the property editor after selecting the table.  

When sorting groups, Tables, Lists and Crosstabs, BIRT supports multiple expressions and the data will be sorted using the first expression, followed by subsequent expressions.  While most sort expressions are quite simple, it is possible to create a custom sort order using a more complicated expression.  Expressions can multi-lined, use report parameters and even call out to external classes.  The following multi-line sort expression returns the third order line number first in the custom sort.

var ol = row["ORDERLINENUMBER"];
if( ol == 3 ){
}else if( ol == 1 ){
}else if( ol == 2 ){
}else if( ol == 4 ){

Sort expressions can also be created and applied in a BIRT JavaScript event handler.  For example the following beforeFactory script adds a sort expression to a table group.

//Name Your Table
tbl = reportContext.getDesignHandle().findElement("mytable");
var lc = new ULocale(reportContext.getLocale());
sc = StructureFactory.createSortKey();
var tblGroup = tbl.getGroups().get(0);
//to put the sort on the table use the table handle
//instead of the group handle
ph = tblGroup.getPropertyHandle(TableHandle.SORT_PROP);

 The examples shown in this post are available at BIRT-Exchange.


Vernon said...

This is cool!

Unknown said...
This comment has been removed by a blog administrator.
Ethereum to Paypal instant Exchange said...

Super leading source website for your ethereum instant exchange purpose, world's most reliable company for cryptocurrency community

Ethereum to Paypal instant Exchange thanks for visiting our link

Credit Loan Solution said...

Are you tired of seeking loans and Mortgages,have you been turned down constantly By your banks and other financial institutions,We offer any form of loan to individuals and corporate bodies at low interest rate.If you are interested in taking a loan,feel free to contact us today,we promise to offer you the best services ever.Just give us a try,because a trial will convince you.What are your Financial needs?Do you need a business loan?Do you need a personal loan?Do you want to buy a car?Do you want to refinance?Do you need a mortgage loan?Do you need a huge capital to start off your business proposal or expansion? Have you lost hope and you think there is no way out, and your financial burdens still persists? Contact us (gaincreditloan1@gmail.com)

Your Name:...............
Your Country:...............
Your Occupation:...............
Loan Amount Needed:...............
Loan Duration...............
Monthly Income:...............
Your Telephone Number:.....................
Business Plan/Use Of Your Loan:...............
Contact Us At : gaincreditloan1@gmail.com
Phone number :+44-7774-038335 (WhatsApp Only)

Dubai Property said...

Dubaiproperty.site is an online real estate advisor that functions on the fundamentals of trust, transparency and expertise. As a digital marketplace with an exhaustive range of property listings.
Dubai Properties
Property for sale in Dubai
Dubai Houses
Buy Property in Dubai
Flat for sale in Dubai
Apartments for sale in Dubai Marina
Real Estate Companies in Dubai
Dubai Hills Estate
Buy Flats in Dubai

Sherwoods Property said...

I love reading through your blog. It’s very interesting blog. Thanks for sharing valuable information to us.Rent Apartments in Dubai