java - how to sort columns in ireport crosstab in a specific scheme -


the following image shows crosstab in ireport:

crosstab

i want sort columns in specific order, knowing in crosstab data, put list of objects list<champetatateliers> following attributes :

public class champetatateliers {      private string numero;     private string denominationfr;     private string etatentreesortie;      public champetatateliers(string numero, string denominationfr, string etatentreesortie) {         this.numero = numero;         this.denominationfr = denominationfr;         this.etatentreesortie = etatentreesortie;     } } 

the etatentreesortie shown in columns, denominationfr shown in rows, , numero used count in crosstab

string rapportlien = "/situationequipement.jasper"; map parametres = new hashmap(); jrbeancollectiondatasource data = new jrbeancollectiondatasource(atelierses); 

in java i'm putting these objects in list atelierses list<champetatateliers>, there way sort columns in list or in crosstab ireport, xml code on ireport follows:

<columngroup name="nbrevehicule" height="66">     <bucket order="descending" class="java.lang.string">         <bucketexpression><![cdata[$f{nbrevehicule}]]></bucketexpression>         <orderbyexpression><![cdata[$v{myorderbyfield_measure}]]></orderbyexpression>     </bucket>     <crosstabcolumnheader>         <cellcontents backcolor="#f0f8ff" mode="opaque">             <textfield>                 <reportelement style="crosstab data text" x="0" y="0" width="85" height="66" uuid="2109b261-1b20-493a-b664-ce59731c4a20"/>                 <box toppadding="1" leftpadding="1" bottompadding="1" rightpadding="1"/>                 <textelement>                     <font isbold="true"/>                 </textelement>                 <textfieldexpression><![cdata[$v{nbrevehicule}]]></textfieldexpression>             </textfield>         </cellcontents>     </crosstabcolumnheader>     <crosstabtotalcolumnheader>         <cellcontents/>     </crosstabtotalcolumnheader> </columngroup> <measure name="myorderbyfield_measure" class="java.lang.integer"  calculation="nothing" >     <measureexpression><![cdata[$f{myorderbyfield}]]></measureexpression> </measure> 

in jasper report crosstab columngroup can sorted ascending or descending setting order attribute on bucket

example

<columngroup name="group" height="16" headerposition="center">     <bucket order="descending" class="java.lang.string">         <bucketexpression><![cdata[$f{myfield}]]></bucketexpression>     </bucket>     ..... </columngroup> 

if need user defined order, should use orderbyexpression

  1. define measure on order

    <measure name="myorderbyfield_measure" class="java.lang.integer" calculation="first">     <measureexpression><![cdata[$f{myorderbyfield}]]></measureexpression> </measure> 
  2. use measure in orderbyexpression

    <columngroup name="group" height="16" headerposition="center">   <bucket class="java.lang.string">     <bucketexpression><![cdata[$f{myfield}]]></bucketexpression>     <orderbyexpression><![cdata[$v{myorderbyfield_measure}]]></orderbyexpression> </bucket> ..... </columngroup> 

in example achieved introducing new field in champetatateliers class example private int myorderbyfield; , via code setting needed.

another solution, return own object (class) myfield , implement comparable, generates desired order.

edit: work around, op can not make orderbyexpression work correctly.

since myorderbyfield unique (related 1 1) nbrevehicule can use myorderbyfield in bucketexpression

<measure name="nbrevehicule_measure" class="java.lang.string">    <measureexpression><![cdata[$f{nbrevehicule}]]></measureexpression> </measure>  <columngroup name="nbrevehicule" height="66">    <bucket class="java.lang.integer">      <bucketexpression><![cdata[$f{myorderbyfield}]]></bucketexpression>    </bucket>    ....    <textfieldexpression><![cdata[$v{nbrevehicule_measure}]]></textfieldexpression>    ..... </columngroup> 

hence bucketexpression not need same text displayed in crosstabcolumnheader


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -