Grid Viewer


Although a lot of thought may have gone into the design of a Crystal report, sometimes users of your JSP application will want to skip the fancy formatting and view data contained in the report in a spreadsheet format. In Crystal Reports , this is referred to as a grid.

You can display a report in a grid by using the Grid Viewer. Create a Grid Viewer simply by declaring an instance of the GridViewer class, as shown here. It is important to keep in mind that the Grid Viewer displays data contained in the report in a format that is independent of the report format.

 GridViewer viewer = new GridViewer(); 
Note  

Like the Interactive Viewer discussed previously, the Grid Viewer is an optional viewer. It is not required for use with the Java Reporting Component. And, like the Interactive Viewer, it is only available if your Java application uses a ReportClientDocument report source from a Report, Application Server.

Once the GridViewer is created, you ll need to associate a report with the Grid Viewer. You do this by calling the setReportSource() method and passing it a reference to the report, as illustrated here:

 viewer.setReportSource(reportSource); 

Next, you can set features of the grid. For example, you can determine whether or not row numbers and column headings are displayed on the grid by calling the setDisplayRowNumberColumn() method, which is defined in the GridViewer class. The setDisplayRowNumberColumn() method requires one argument, which is a constant that identifies your selection.

The available constants for the CrDisplayRowNumberColumnEnum are

  • crDisplayRowNumberColumnYesWithoutHeading

  • crDisplayRowNumberColumnYesWithHeading

  • crDisplayRowNumberColumnNo

  • crDisplayRowNumberColumnYesWithoutHeading

Rows in the grid can be displayed grouped or ungrouped ( ungrouped grids are referred to as flat reports). You can group or ungroup rows by setting the GridViewMode using the setGridViewMode() method. The setGridViewMode() method requires one argument, which is one of the following constants, available in the CrGridViewModeEnum class:

  • crViewModeGroup

  • crViewModeFlat

  • crViewModeGroup

Another common feature that you will want to set is the width of the grid. Typically, you ll want to have the grid as wide as the toolbar. You do this by passing a Boolean value of true to the setMatchGridAndToolbarWidths() method, as shown here:

 viewer.setMatchGridAndToolbarWidths(true); 

Once you ve created the Grid Viewer, designated a report to be viewed , and set properties of the grid, you are ready to display the grid. This is done by calling the processHttpRequest() method, as illustrated here:

 viewer.processHttpRequest(request, response, getServletConfig().getServletContext(), null); 

The following is the completed JSP application. Figure 23-3 shows the screen that this application displays.

click to expand
Figure 23-3: Report displayed in Grid Viewer
 <%@ page import="com.crystaldecisions.report.web.viewer.GridViewer, 
com.crystaldecisions.report.web.viewer.CrDisplayRowNumberColumnEnum,
com.crystaldecisions.report.web.viewer.CrGridViewModeEnum"%>
<%
GridViewer viewer = new GridViewer();
viewer.setReportSource(reportSource);
viewer.setDisplayRowNumberColumn(CrDisplayRowNumberColumnEnum.
crDisplayRowNumberColumnYesWithoutHeading);
viewer.setGridViewMode(CrGridViewModeEnum.crViewModeGroup);
viewer.setMatchGridAndToolbarWidths(true);
viewer.processHttpRequest(request, response, getServletConfig().
getServletContext(), null);
%>



Crystal Reports 10
Crystal Reports 10: The Complete Reference
ISBN: B005DI80VA
EAN: N/A
Year: 2004
Pages: 223
Authors: George Peck

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net