IMPORTANT: to make this work for Dashboards in TIBCO JasperReports@ Server versions 6.4.2 and later, replace define(function(require) with define("dashboardHyperlinkHandlerUpdateDashboardParams", function(require) in the JavaScript file described in this article, as per ktalarico's comment below.
For a single Report outside a Dashboard, see example at the bottom of this article.
Problem
Drill-down or drill-across hyperlinks in a Dashboard are available out of the box in Ad Hoc Dashlets (Hyperlinks tab in Dashlet Properties), but not in Dashlets containing production reports designed in TIBCO Jaspersoft® Studio. A possible solution is using a custom hyperlink handler.
For cross-linking in a Dashboard, the same approach is required in both cases - See a complete implementation here: https://github.com/ernestoongaro/jrs-helper-scripts/tree/master/crosslink-dashboard
Here's the related section from the JasperReports Ultimate Guide (p.166 of the PDF):
CUSTOM HYPERLINKS
In addition to the standard hyperlink types, users can define hyperlinks having custom types. A custom-typed hyperlink can have arbitrary parameters and is meant to be processed by a hyperlink handler registered while exporting the report.
When a hyperlink is declared as having a type other than the built-in types, the hyperlink is considered of custom type and the user is expected to provide handlers to process the hyperlink when the report is exported. Arbitrary hyperlink parameters can be added to a custom hyperlink using the <hyperlinkParameter> tag. These parameters are made available to the custom hyperlink handler so that it can generate a final hyperlink depending on the parameter values. Hyperlink parameter expressions are evaluated along with the hyperlink, and the results are kept in the generated hyperlink object as parameter values.
When exporting the report to other formats such as HTML or PDF, the user can set a factory of hyperlink handlers using the HYPERLINK_PRODUCER_FACTORY export parameter. A factory is an implementation of net.sf.jasperreports.engine.export.JRHyperlinkProducerFactory, which is responsible for creating a hyperlink handler for a custom hyperlink type. This hyperlink handler created by the factory is a net.sf.jasperreports.engine.export.JRHyperlinkProducer instance, and it is used for generating a hyperlink reference in the export document by assembling hyperlink parameters and other information supplied at export time.
To handle custom hyperlinks in the built-in Swing viewer, you need to register a hyperlink listener by calling addHyperlinkListener(listener) on the net.sf.jasperreports.view.JRViewer component. The listener is an implementation of the net.sf.jasperreports.view.JRHyperlinkListener interface. When a report hyperlink gets clicked, the listener queries the hyperlink type and performs the desired actions.
Limitations
The sample code below was tested in JasperReports Server 6.1 and might not work in previous or following releases.
Additionally, it will only work when viewing a saved Dashboard and will not work when previewing it from the Dashboard Designer.
Solution
Create a custom hyperlink type in your main report. Here's an example for an HTML5 chart. In this case we named it "UpdateDashboardParams":
<hc:series name="Measure1"> <hc:contributor name="SeriesItemHyperlink"> <hc:contributorProperty name="hyperlinkType" valueType="Constant" value="UpdateDashboardParams"/> <hc:contributorProperty name="area" valueType="Bucket" value="State.area"/> </hc:contributor> </hc:series>
Here's an example for other elements:
Create a new Dashboard and put all your reports on canvas
Go to Filter Manager in the Dashboard and manually create a filter (will create a section named "Manually Created Filters") with the same name as it is produced by your custom hyperlink. In this example it is "area". Then wire it to corresponding parameters in your "child" reports:
Save the Dashboard.
Create a custom handler for your new hyperlink type, save it as dashboardHyperlinkHandler<YOUR_HYPERLINK_TYPE>.js (in this case it is dashboardHyperlinkHandlerUpdateDashboardParams.js) and put it to both /scripts and /optimized-scripts folders of your server deployment:
define(function(require) { "use strict"; var $ = require("jquery"), _ = require("underscore"); return { events: { click: function(event, linkData) { if (window.location.href.indexOf("dashboard/viewer") > -1) { var hashParts = window.location.hash.split("&"), reportUri = hashParts[0], params = {}; for (var i = 1; i < hashParts.length; i++) { if (hashParts[i].indexOf("=") > 0) { var key = hashParts[i].split("=")[0], value = hashParts[i].split("=")[1]; if (key in params) { params[key].push(value); } else { params[key] = [value]; } } } location.replace(reportUri + "&" + $.param(_.extend(params, linkData.parameters), true)); } } } } });
Open your dashboard in Dashboard Viewer and try hyperlinks.
To make hyperlinks work in Visualize.js, you'll have to override linkOptions:
linkOptions: { events: { click: function(ev, link, defaultHandler) { if (link.type === "UpdateDashboardParams") { dashboard.params(convertParams(link.parameters)).run(); } else { defaultHandler(); } } } }
A working Viz.js sample can be found at http://jsfiddle.net/v6a23vz7/
Just update the host name to your server and dashboard URI if needed.
For a single Report
For a single Report not in a Dashboard, see the attached example jasperreports-custom-hyperlink-handler.jar.
The Javascript is inside the JAR that you need to deploy to WEB-INF/lib of JasperReports Server. After deploying that file and restarting the instance, import export-expandcollapse.zip (also attached) into organization_1 as superuser: 'Manage' > 'Organizations' > right-click on 'Organizations' > 'Import...'.
Then you can test this sample "expand/collapse" functionality in this report: '/Public/Accounts Report'.
Recommended Comments
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now