2013-02-07 30 views
0

主報告使用包含列表(父列表)的數據源。 此列表(parentList)又包含其他列表(childList)。 This childList作爲DataSource(JRBeanCollectionDataSource)傳遞給SubReport。比較數據源中的行以打印特定記錄

This childList包含兩列,下面是列表的表格格式。

<pre>TestString | Date</pre> 
<pre> abc | 01JAN12 </pre> 
<pre> cdf | 31DEC12 </pre> 
<pre> fgh | 08JUN12 </pre> 

從上面的表格,日期應該是比較得到的紀錄在這種情況下,最新的日期(即)CDF了「的TestString」值。

比較行或記錄應該在Jasper報告中完成,而不是在java類中。

我該怎麼做?

+0

DataSource是一個SQL表嗎? –

+0

它的JRBeanCollectionDataSource對象 –

+0

JRBeanCollectionDS集合中的對象是什麼?實現一個'比較器'來根據此集合中的日期對對象進行排序。您可以使用'SimpleDateFormat'來分析日期字符串。 –

回答

3

你必須做,在Java方面

假設你有POJO結構

public class Parent{ 
    private List<Child> childList; 
    ... 
} 

public class Child{ 
    String testString; 
    Date date; 
} 

,做報表生成

... 
List<Parent> parent = //method for getting datasource 
List<String> testStrings = getTestStrings(parent); 
... 
//pass the list of testStrings to the report 
//inside the report, create a parameter of type List 
//pass list.get($V{ctr}) to the subreport where ctr is the current count of the subreport, make it start with 0 

getTestStrings方法應該做些什麼的Java方法中像

private List<String> getTestStrings(List<Parent> parent){ 
    //loop through parent list 
    //pull each child list then do the sort by date then get(0).getTestString() 
    //put the value in a list 
    //return the list 
} 
+0

謝謝@onepotato :) 我會試試這個。我只是想知道我們是否可以在Jasper Reports中做到這一點。(Sorting and Stuff) –

+1

不,jasper報告僅用於顯示通過它們的任何數據。 – Bnrdo

+0

但我聽說在碧玉中使用** Variables **會做到這一點。 –