Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There may be much easier and straight forward solutions:</p> <p>I am using Jasper Reports Studio (Eclipse Plugin).</p> <ol> <li><p><strong>did not finally work for me :-( ...</strong> (see 1. comment below my answer - may be a bug) you just can check <strong><em>[x] Data Pre Sorted</em></strong> in the <strong><em>Crosstab Properties</em></strong>. Of course this only works if you do not need another ordering somewhere else in the report based on the pre-sorted result set.</p></li> <li><p>using an <strong><em>invisible crosstab group header</em></strong>, which is rather tricky:</p> <ol> <li><strong>create a new row/column group</strong> (e.g. via Outline view), leave the initial name <code>Row Group1</code> or similar as is for now</li> <li><strong>set its <code>Total Position</code> to <code>None</code></strong> (we do not want to have a total column per row/column generated)</li> <li><strong>move the group in the XML before the old one</strong></li> <li><strong>rename the group</strong> to some speaking name, <strong>e.g. <code>name="invisible sort column ..."</code></strong> <ul> <li>(no further references to this group should exist in the XML anymore)</li> </ul></li> <li><p>if you are <strong>using group totals</strong> on your group (<strong><code>Total Position</code> != <code>None</code></strong>) then you have to <strong>basically move these totalling elements/settings to the first dummy sort group</strong>, because otherwise the totals will be no totals anymore (= per 2nd group totals) displayed after each group column/row, e.g. (here only shown with column group, but row group follows the same principle) </p> <pre><code>a|b|c|sum a|sum|b|sum|c|sum ========= =&gt; ================= 1|2|3|6 1|1 |2|2 |3|3 </code></pre> <ul> <li><p>easiest may be to do this in the XML similar to this transformation (do not forget to move the <code>totalPosition=...</code> and <code>columnTotalGroup=...</code> attributes and to change the sum if applicable to your scenario <code>$V{SomeSum_..._ALL}</code>):</p> <pre><code>... &lt;columnGroup name="OrderXDummy" height="0"&gt; ... &lt;crosstabTotalColumnHeader&gt; &lt;cellContents/&gt; &lt;/crosstabTotalColumnHeader&gt; &lt;/columnGroup&gt; ... &lt;columnGroup name="X" ... totalPosition="End"&gt; ... &lt;crosstabTotalColumnHeader&gt; &lt;cellContents ...&gt; ... &lt;/cellContents&gt; &lt;/crosstabTotalColumnHeader&gt; &lt;/columnGroup&gt; ... &lt;crosstabCell ... columnTotalGroup="X"&gt; ... &lt;textFieldExpression&gt;&lt;![CDATA[$V{SomeSum_X_ALL}]]&gt;&lt;/textFieldExpression&gt; ... &lt;/crosstabCell&gt; </code></pre> <p>=></p> <pre><code>... &lt;columnGroup name="OrderXDummy" height="0" totalPosition="End"&gt; ... &lt;crosstabTotalColumnHeader&gt; &lt;cellContents ...&gt; ... &lt;/cellContents&gt; &lt;/crosstabTotalColumnHeader&gt; &lt;/columnGroup&gt; ... &lt;columnGroup name="X" ... &gt; ... &lt;crosstabTotalColumnHeader&gt; &lt;cellContents/&gt; &lt;/crosstabTotalColumnHeader&gt; ... &lt;/columnGroup&gt; ... &lt;crosstabCell ... columnTotalGroup="OrderXDummy"&gt; ... &lt;textFieldExpression&gt;&lt;![CDATA[$V{SomeSum_OrderXDummy_ALL}]]&gt;&lt;/textFieldExpression&gt; ... &lt;/crosstabCell&gt; </code></pre></li> </ul></li> <li><p>(may be skipped:) <strong>remove unnecessarily generated <code>&lt;crosstabCell ... column/rowTotalGroup="..."&gt;</code></strong> cells</p> <ul> <li>its maybe best to compare the report with a previous version to reliably and fast identify these spots in the XML</li> <li>maybe this is not a crucial step, but looking at the existing XML is confusing enough ;-)</li> </ul></li> <li><strong>add</strong> the <strong>(bucket) expression</strong> of your sort column, <strong>e.g. <code>$F{ORDER_FOR_X}</code></strong> <ul> <li>don't forget to assign <strong><code>Value Class Name</code></strong> to <code>java.lang.Integer</code> or whatever fits for your values here (have a look at your dataset which type is assigned there if your are using it via some column)</li> </ul></li> <li><p><strong>add</strong> some variable <strong>expression to the <code>Order By Expression</code> of the original group, e.g. <code>$V{ORDER_FOR_X}</code></strong></p> <ul> <li><strong><code>$V{...}</code></strong> is the trick, do not use <code>$F{...}</code>!</li> <li>(the editor says it's invalid, but it will work)</li> <li><p>meaning if you can provide some field that defines the sort and relates to your to-be-sorted column value, e.g. (Oracle SQL)</p> <pre><code>select 1 as order_for_x, 'foo' as x, 'bla blu' as y from dual union all select 2, 'bar', 'ta tu' from dual union all select 2, 'bar', 'na na' from dual union all select 1, 'foo', 'check it' from dual union all select 3, 'queue', 'sap' from dual </code></pre></li> <li><p>otherwise you can of course use something else here as well</p></li> <li><p>if you should get some </p> <pre><code>... Caused by: java.lang.NullPointerException at org.apache.commons.collections.comparators.ComparableComparator.compare(ComparableComparator.java:92) at net.sf.jasperreports.crosstabs.fill.BucketExpressionOrderer.compareOrderValues(BucketExpressionOrderer.java:70) ... </code></pre> <p>you can simply change the expression to <code>$V{ORDER_FOR_X} == null ? 0 : $V{ORDER_FOR_X}</code> which should do the trick</p></li> </ul></li> <li><p><strong>set all high/width fields</strong> of the dummy group <strong>to <code>0</code></strong> and the <strong>text fields <code>Print When Expression</code> to <code>false</code></strong></p></li> <li>(maybe check via compare with the previous report version that nothing else has changed to make sure you didn't mess up something else)</li> </ol></li> <li><p>using an <strong><em>order by based on measure totals</em></strong> (as described in the bottom link)</p></li> <li><p>using a <strong><em>custom Java Comparator class</em></strong> (as described in the answer from <a href="https://stackoverflow.com/a/8153225/1915920">Pieter VN 2011-11-16</a>)</p></li> </ol> <p>further maybe helpful links I found:</p> <ul> <li><a href="http://community.jaspersoft.com/wiki/custom-crosstab-ordering-ireport-designer" rel="nofollow noreferrer">http://community.jaspersoft.com/wiki/custom-crosstab-ordering-ireport-designer</a></li> <li><a href="http://community.jaspersoft.com/questions/506284/combined-crosstabs" rel="nofollow noreferrer">http://community.jaspersoft.com/questions/506284/combined-crosstabs</a></li> <li><a href="http://jasperreports.sourceforge.net/schema.reference.html" rel="nofollow noreferrer">http://jasperreports.sourceforge.net/schema.reference.html</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload