| By Jason Weathersby | Article Rating: |
|
| June 10, 2010 01:30 PM EDT | Reads: |
3,866 |
Just ran across this and it is a nice technique for those situations where you are limited to table based filtering of data. Typically, I focus on data filtering as far up stream as possible. It is better to filter data at the source (in the where clause for JDBC). Next, I use DataSet based filtering.
But sometimes you can't filter at the Source or the DataSet, which is where table based filtering comes in. The issue with table based filters is that there is no good way in the UI to implement conditional filtering. For instance, imagine you have a data driven parameter multi-select parameter and you want to limit the choices to the values from that parameter.
This is relatively simple to do, you just create a multi-select parameter and add a filter to a table.
So what happens if your user wants to select all of the values in the list? They need to select each of the values from the pick list that appears. Unfortunately, with large pick lists this is a little tricky for the end user. In addition, table based filtering on large pick list may create performance issues.
What you would like to do is make the parameter optional, and if the value for the parameter is not set, then just don't filter on that parameter value.
The UI does not support this type of behavior, but it is easy to do through a small amount of script on the table in the onPrepare method.
importPackage( Packages.org.eclipse.birt.report.engine.api.script.element );
importPackage( Packages.org.eclipse.birt.report.model.api.simpleapi );
if(params["Region"].value!= null){
var filterCondition = StructureScriptAPIFactory.createFilterCondition();
filterCondition.setExpr("row['COUNTRY']");
filterCondition.setOperator("eq");
filterCondition.setValue1("params[\"Region\"]");
var filterKey = filterCondition.getStructure();
var filterItem = SimpleElementFactory.getInstance().createFilterCondition( filterKey )
this.addFilterCondition( filterItem );
}
Now how would you handle the situation if you had multiple filter conditions that you wanted to add? A trivial re-factor and you can create a general purpose method add filter method.
// generic function to add a filter to a table
function addFilterItem (table, rowExpr, paramExpr){
var filterCondition = StructureScriptAPIFactory.createFilterCondition();
filterCondition.setOperator("in");
filterCondition.setExpr(rowExpr);
filterCondition.setValue1(paramExpr);
// could do in one step, shows DEAPI creation steps
var filterKey = filterCondition.getStructure();
var filterItem = SimpleElementFactory.getInstance().createFilterCondition( filterKey );
table.addFilterCondition(filterItem);
}
This method can then be placed into a JavaScript file, a Script extension point, or a global location. Calling the file from the table is equally easy.
// add filters dynamically
if (params["Country"].value != null )
addFilterItem (this, 'row["COUNTRY"]' , 'params["Country"].value' );
if (params["City"].value != null)
addFilterItem (this, 'row["CITY"]' , 'params["City"].value' );
It is important to recognize that the second and third parameters that are being passed are expressions and not values. So what is happening is we are creating a filter, and that filter will use the express row["COUNTRY"] to look up the appropriate country values. That is why you need to pass the exact expression through in the function.
If you are having trouble figuring out the appropriate expression, just build the expression that you want in the UI, and then search through the XML for the word filter. You will see the expressions in the XML. Just copy these expressions and pass them to your function. Just delete the static filter and you are all set. Yes, you can use different operators then the IN clause, but it seems the most appropriate for this type of filtering.
Read the original blog entry...
Published June 10, 2010 Reads 3,866
Copyright © 2010 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Jason Weathersby
Jason Weathersby is a member of the extended BIRT development team at Actuate Corporation and has backgrounds in both computer science and technical writing. He has many years experience in technical consulting, training, writing, and publishing about reporting, business intelligence tools, and database technologies.
- It's the Java vs. C++ Shootout Revisited!
- Patterns for Building High Performance Applications
- Asynchronous Logging Using Spring
- Java for Programmers (2nd Edition)
- Cross-Platform Mobile Website Development – a Tool Comparison
- Write Once Run Anywhere or Cross Platform Mobile Development Tools
- Three Buzzwords That Every CIO Hears but One They Should Listen To
- Immersing into JavaScript Frameworks
- Workday Reportedly Prepping to Go Public
- Cloud Expo New York: The Java EE 7 Platform - Developing for the Cloud
- Book Review: Sams Teach Yourself Java in 24 Hours
- OpenOffice.com Lives
- Book Excerpt: Introducing HTML5
- Adobe Sends Flex to the Apache Foundation
- Five Years Waiting for JRE 7: Is It Justified? (Part 1)
- Book Excerpt: Java Application Profiling Tips and Tricks
- i-Technology in 2012: Five Industry Predictions
- It's the Java vs. C++ Shootout Revisited!
- Patterns for Building High Performance Applications
- OpenXava 4.3: Rapid Java Web Development
- The Next Web Architecture
- Asynchronous Logging Using Spring
- Java for Programmers (2nd Edition)
- Is Write Once Run Anywhere Ever Going to Be a Reality?
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- JavaServer Faces (JSF) vs Struts
- The i-Technology Right Stuff
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- What's New in Eclipse?
- i-Technology Predictions for 2007: Where's It All Headed?


















