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 ){
1
}else if( ol == 1 ){
2
}else if( ol == 2 ){
3
}else if( ol == 4 ){
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.


importPackage(Packages.org.eclipse.birt.report.model.api);
importPackage(Packages.org.eclipse.birt.report.model.api.elements);
importPackage(Packages.java.util);
importPackage(Packages.com.ibm.icu.util);
//Name Your Table
tbl = reportContext.getDesignHandle().findElement("mytable");
var lc = new ULocale(reportContext.getLocale());
sc = StructureFactory.createSortKey();
sc.setKey("row[\""+params["SortOn"].value+"\"]");
sc.setDirection(params["SortOrder"].value);
sc.setLocale(lc);
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);
ph.addItem(sc);

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




20 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete


  2. This article is really informative ,from this article i have learned something and tried which really help me.


    ReplyDelete
  3. "Great comparison! It's interesting to see how BIRT, Jaspersoft, and Pentaho have evolved over time. Thanks for the detailed insights!"
    Namkeen Distributorship
    Centrifugal Blowers

    ReplyDelete
  4. "Fantastic breakdown! I appreciate the inclusion of sorting details for BIRT — it really helped clarify a few things for me."
    Mezzanine Floor manufactrurer in Delhi
    Warehouse Rack in Noida

    ReplyDelete
  5. "Thanks for the article. I was confused between Jaspersoft and Pentaho, but this comparison has made it clearer. Well done!"
    Dust Collector Manufacturer delhi
    pulse jet bag filter manufacturer

    ReplyDelete
  6. "Can you go a bit deeper into the comparison matrix? I'd love to know which tool is best for handling large datasets."
    Industrial Exhaust Fan Manufacturer
    Steel Mezzanine Floor in Delhi

    ReplyDelete
  7. "Nice post! The sorting feature in BIRT sounds flexible, especially for grouped data. I’ll be exploring this further."
    modular mezzanine floor in ranchi
    Warehouse Racking System in Indore

    ReplyDelete
  8. "This comparison is really helpful! I've been thinking about switching from Pentaho to Jaspersoft, so this helps a lot."
    Filing Compactor in Delhi
    Industrial Storage Racks Ranchi

    ReplyDelete
  9. "The BIRT sorting feature explanation was really clear. It’s impressive how customizable BIRT is for sorting and grouping."
    modular mezzanine floor india
    Fifo Flow Rack Manufacturer

    ReplyDelete
  10. "Interesting insights! Would love to see an update on performance benchmarks for each of these tools."
    mezzanine floor faridabad
    Industrial Storage rack manufacturer

    ReplyDelete
  11. "Thank you for the article! It was great to get an unbiased look at these tools. Looking forward to more updates!"
    fabric storage rack manufacturer
    perforated cable tray manufacturer

    ReplyDelete
  12. "I had no idea about the 'Sort by groups' feature in BIRT. This is going to save me a lot of time on my reports
    industrial mezzanine floor delhi
    heavy duty rack faridabad

    ReplyDelete
  13. "Would you recommend any of these tools specifically for small businesses with limited technical expertise?"
    mezzanine floor rudrapur
    office chair in delhi

    ReplyDelete
  14. "The group sorting options in BIRT are just what I needed! Thanks for sharing this. Very informative article."
    Franchise Event
    Namkeen Distributorship

    ReplyDelete
  15. Anonymous9:17 PM

    "I’ve used Pentaho in the past, and this review makes me want to give BIRT a try. Thanks for the in-depth analysis."
    Gym Franchise

    ReplyDelete
  16. "Are there any tutorials on your site that show how to use the advanced sorting in BIRT? That feature sounds powerful."
    Argan Oil Manufacturer in Korea
    Sparsh Bagga

    ReplyDelete
  17. "Great read! I’m curious, which tool would you recommend for reports that need frequent updates or real-time data
    SEO Agency in India
    Automatic web Sealer

    ReplyDelete
  18. "I appreciate the practical examples in this post. Sorting options can be confusing, but your explanation made it easier to follow."
    Spices Distributorship
    Pulse Jet Bag filter

    ReplyDelete
  19. Anyone looking for a reliable Cooling Tower should definitely check out Kooldrop. We offer high-quality FRP Cooling Tower, Wooden Cooling Tower, and complete Industrial Cooling Tower solutions. Our products are durable, long-lasting, and ideal for all types of industrial needs. Feel free to contact us for more information.

    ReplyDelete