• Home
  • Data Sources
  • JavaScript

logo

  • Charts
  • Create a Simple Listing Report
  • Create a Simple Listing Report Preview
  • Data Sources
  • EXMIS Data Cleanup Team Dashboard
  • Welcome to MrBIRT.com


BIRT Dynamic Sorting by Column Header

In the first lessons of BIRT, you learn how to set up a sort.  But the sort that you learn is static.  You can set it up, but once the report runs, the user has no control over how the data sorts.

In this lesson, you will learn dynamic sorting in BIRT.  That means that the user can reorganize how the data is presented simply by clicking on the column header.

This is a quick lesson on how to set it up.

First, make a copy of the Customers.rptdesign folder that you should already have ( if you are following along in the lessons).  If not, you can download the file from mrbirt.com.

Rename the copied file to:  Customers-dynamic-sort-BIRT.rptdesign.

Open the file.

There a several things that we need to do to make the sort dynamic.

 

First of all, we need to create a new report parameter (as shown).
Name:  rp_SortOrder
Data Type: Integer
Display Type: Text Box
Default Value: 0
Select following Check boxes:  “Is Required”
“Hidden”

Create Drill-Through Hyperlink

  1. Select the “Customer” label in the header of the table.
  2. Select “Properties” from the Property Editor.
  3. Select the “Hyperlink” tab
  4. Click the “Edit…” button

Hyperlink Options

  1. Select Drill-through.
  2. Select “BIRT-Dynamic-Sort-Customers.rptdesign”
  3. Select “Same Frame” for “Show Target Report”.
  4. Type “Sort by Customer” for a “Tool Tip”.
  5. Click the “Add…” button

Add Hyperlink Parameter:

  1. Select “rp_SortOrder” from the Parameter drop-down menu.
  2. Click the “Expression Builder” button next to the “Value” field.

Copy and paste the following code into the “Expression Builder” window:

// CUSTOMERNAME

if(params[“rp_SortOrder”].value == 0) { 1 } else if(params[“rp_SortOrder”].value == 1) { 2 } else { 1 }

 

When your screen matches the screenshot here, you’re ready to move on.  Click OK.

 

Next, select the “Table” tab.  Then, select the “Script” editor.   Be sure the “Table” tab is selected or it will not work properly.

Adding the Sorting Script

  1. Make sure that your “Script” editor shows “Table” as the object you are working on.
  2. Set the Script drop-down menu to “onPrepare”
  3. Copy and paste the provided code into the “Script” editor.

Click Preview.

The “Customer” header is now sortable!  Click it a few times.

The sort goes from ASC and back to DESC order.

You can now apply the same techniques to any of the other headers so that your report is now sortable using multiple columns.

 

 

About the Author
Sean is a technology enthusiast and an independent consultant. He has been authoring tech training articles and videos for 7 years. He has a Bachelors of Science degree from the United States Military Academy.

Create Simple Listing Report: 8 Tasks

Create New Project-featured image
1: Create New Project
How-to-Create-New-Report-in-BIRT
2: Create New Report
Click Data Sources to Connect to an existing database
3: Build Data Source
image-BIRT-Build_A_Data_Set
4: Build Data Set
Layout-the-report--Palette-Tools-featured
5: Lay out the Report
image-BIRT-time-to-sort-data
6: Sort the Data
image-Format-the-Report-mini-tasks
7: Format the Report
Use the Palette to Format-the-Report-ideas-featured image
8: Create Report Title