logicalfox
logicalfox

Reputation: 83

Jasper Reports - How to sort crosstab when using multiple measures

I have created a crosstab in Jasper Studio which shows Sales, Quantity, and Percentage Margin totals for a client. The major complexity of this crosstab is the Percentage Margin, as this cannot use a simple sum, count, or average in the total to report the correct figure, it needs to be calculated separately. To combat this I have created 4 measures:

  1. for the main data (a combination of sales, quantity, and margin in 1 field)
  2. for the right-hand total
  3. for the bottom-line summary, and
  4. for the Overall totals field where total and summary meet.

enter image description here

The client requires the crosstab to be sorted at runtime using the interactive sorting feature of Jasper Server. This is working, but only as long as the crosstab uses one measure. As soon as I add the other 3 measures, the sorting option for all columns greys-out, and the sort no longer works for the client.

Is there any way I can make this sorting work, even when I use multiple Measures? Or is there another way I can display the information I require using a single measure instead?

Upvotes: 0

Views: 1570

Answers (1)

dada67
dada67

Reputation: 5093

What you need to do is to set the net.sf.jasperreports.crosstab.column.header.sort.measure.index property on an element in the column header cell to the 0-based index of the measure that you want the column sorted by.

As in

<columnGroup ...>
    ...
    <crosstabColumnHeader>
        <cellContents>
            <textField>
                <reportElement ...>
                    <!-- sort by the second measure -->
                    <property name="net.sf.jasperreports.crosstab.column.header.sort.measure.index" value="1"/>
                </reportElement>

Upvotes: 0

Related Questions