【问题标题】:Column and table headers in same data source as data itself (json data source)与数据本身相同的数据源中的列和表标题(json 数据源)
【发布时间】:2017-11-06 18:39:35
【问题描述】:

我的报告中有一个表格元素的 json 数据源。我的 json 是-

[{
        "line_num": {
            "oldVal": "1",
            "newVal": "5"
        },
        "product1": {
            "oldVal": "product1old",
            "newVal": "product1new"
        }
}, {
    "line_num": {
        "oldVal": "4",
        "newVal": "7"
    },
    "product2": {
        "oldVal": "product2old",
        "newVal": "product2new"
    }
}
]

这对我的报告有用,但是我需要从数据源添加列和表标题。

所以我尝试将它作为自己的对象添加到上面的 json 数组中,如下所示:

[{
        "tableH": "My Table Header"  ,         
        "col1H": "Line No."  ,     
        "col2H": "My Product"  
    }, {
        "line_num": {
            "oldVal": "1",
            "newVal": "5"
        },
        "product1": {
            "oldVal": "product1old",
            "newVal": "product1new"
        }

    }, {
        "line_num": {
            "oldVal": "4",
            "newVal": "7"
        },
        "product2": {
            "oldVal": "product2old",
            "newVal": "product2new"
        }
    }
]

但问题是,当有很多行大于页面高度时,第二页上的标题为空,这是有道理的,因为从第二行开始,第一个 obj(标题 obj)是未知的,

但我不知道如何以另一种方式从服务器传递我的标头。

唯一可行的方法是将所有标题添加到数组中的每个 obj 中,但我不能这样做,因为它明显错误。

我也尝试将这些行作为一个数组,如下所示:

[{
        "tableH": "My Table Header"  ,        
        "col1H": "Line No."  ,        
        "col2H": "My Product"  ,
        "Lines": [{
                "line_num": {
                    "oldVal": "1",
                    "newVal": "5"
                },
                "product1": {
                    "oldVal": "product1old",
                    "newVal": "product1new"
                }

            }, {
                "line_num": {
                    "oldVal": "4",
                    "newVal": "7"
                },
                "product2": {
                    "oldVal": "product2old",
                    "newVal": "product2new"
                }
            }
        ]
    }
]        

但随后字段未正确传递,例如通过 -lines.line_num.newVal ,该字段为:["5","7"]。

我真的需要这方面的帮助,如果有任何有用的回复,我将不胜感激。

【问题讨论】:

  • 我们可以使用一些示例 .jrxml 文件来了解您想要的输出。你真的需要使用桌子吗?您使用的是什么版本的 JasperReports?

标签: jasper-reports


【解决方案1】:

将数据集与静态数据混合似乎是个坏主意。我的第一次尝试是通过 scriptlet 获取静态数据。

否则,您可以在组标题组件中添加列名,并利用组的isReprintHeaderOnEachPage 属性提供的功能。

http://jasperreports.sourceforge.net/schema.reference.html#group_isReprintHeaderOnEachPage

【讨论】:

    猜你喜欢
    • 2020-03-11
    • 2016-12-23
    • 2011-04-20
    • 2016-12-11
    • 2013-01-05
    • 1970-01-01
    • 1970-01-01
    • 2021-12-09
    • 1970-01-01
    相关资源
    最近更新 更多