iReport Ultimate Guide - Nimsoft Library

iReport Ultimate Guide - Nimsoft Library iReport Ultimate Guide - Nimsoft Library

13.07.2015 Views

iReport Ultimate GuideUR groups records by evaluating the group expression. Every time the expression’s value changes, a new groupinstance is created. The engine does not perform any record sorting if not explicitly requested, so when we define groups weshould always provide for the sorting. For instance, if we want to group a set of addresses by country, we have to sort therecords before running the report. We can use a SQL query with an ORDER BY clause or, when this is not possible (that is,when obtaining the records from a data source which does not provide a way to sort the records, like an XML document or anExcel file), we can request that UR sort the data for us. This can be done using the sort options available in theiReport query window (Figure 7-5).Figure 7-5Sorting OptionsIn order to use the Sort options, you must have some fields already registered in the report. Sorting can only be performed onfields (you cannot sort records using an expression). You can define a sort using any of the fields in the database. Each fieldcan use a different sort type (ascending or descending). The sorting is performed in memory, so it’s use is discouraged if youare working with very large amounts of data, but it is useful with a reasonable number of records (depending on the availablememory).Let’s see how groups work in an example. Suppose you have a list of people. You want to create a report where the names ofthe people are grouped last-name-first as in a phone book. Run iReport and open a new empty report. Next, take the data froma database by using a SQL query with a proper ORDER BY clause (we will use the sample database provided withUR). For this example, use the following SQL query:SELECT * FROM ADDRESS ORDER BY LASTNAME, FIRSTNAMEThe selected records will be ordered according to the last then first name of the customers. The fields selected by the queryshould be ID, FIRSTNAME, LASTNAME, STREET and CITY.114

Bands and GroupsFigure 7-6Dragging a field into the Detail bandBefore continuing with creating your group, make sure that everything works correctly by inserting in the Detail band theFIRSTNAME, STREET and CITY fields (move them from the outline view to the Detail band, as shown in Figure 7-6).Then create a layout similar to the one proposed in Figure 7-7 and preview the report.Figure 7-7Layout before adding the groupsThe result should be similar to that of Figure 7-8.115

Bands and GroupsFigure 7-6Dragging a field into the Detail bandBefore continuing with creating your group, make sure that everything works correctly by inserting in the Detail band theFIRSTNAME, STREET and CITY fields (move them from the outline view to the Detail band, as shown in Figure 7-6).Then create a layout similar to the one proposed in Figure 7-7 and preview the report.Figure 7-7Layout before adding the groupsThe result should be similar to that of Figure 7-8.115

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!