admin管理员组文章数量:1026989
I have a JSON like this
{
"details": [
{
"name": "Name 1",
"head": [
{
"isin": "ISIN 1",
"coupon": "Coupon 1"
}
]
},
{
"name": "Name 2",
"head": [
{
"isin": "ISIN 2",
"coupon": "Coupon 2"
}
]
}
]
}
and I want to show a nested table like this
Name 1 |
---|
I have a JSON like this
{
"details": [
{
"name": "Name 1",
"head": [
{
"isin": "ISIN 1",
"coupon": "Coupon 1"
}
]
},
{
"name": "Name 2",
"head": [
{
"isin": "ISIN 2",
"coupon": "Coupon 2"
}
]
}
]
}
and I want to show a nested table like this
Name 1 |
---|
ISIN 1 | Coupon 1 |
---|
Name 2 |
---|
ISIN 2 | Coupon 2 |
---|
My report is here
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport uuid="13bb06fa-a8ce-41f8-b3e4-a094f892f221">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="JSONAdapter"/>
<subDataset name="datasetDetails" uuid="3f8c902f-fffd-48fe-b65f-46e976854490">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="JSONAdapter"/>
<queryString language="json">
<![CDATA[details]]>
</queryString>
<field name="name" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="name"/>
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<field name="head" class="net.sf.jasperreports.engine.data.JsonDataSource">
<property name="net.sf.jasperreports.json.field.expression" value="head"/>
<fieldDescription><![CDATA[head]]></fieldDescription>
</field>
</subDataset>
<subDataset name="datasetDetailsHead" uuid="a91998cc-c1fa-4802-868d-90cb9a24636d">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="JSONAdapter"/>
<queryString language="json">
<![CDATA[details.head]]>
</queryString>
<field name="isin" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="isin"/>
<fieldDescription><![CDATA[isin]]></fieldDescription>
</field>
<field name="coupon" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="coupon"/>
<fieldDescription><![CDATA[coupon]]></fieldDescription>
</field>
</subDataset>
<queryString language="JSON">
<![CDATA[]]>
</queryString>
<detail>
<band>
<componentElement>
<jr:table xmlns:jr="http://jasperreports.sourcefe/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourcefe/jasperreports/components http://jasperreports.sourcefe/xsd/components.xsd">
<datasetRun subDataset="datasetDetails" uuid="3ca38bbd-cd5a-44c4-98bb-2e993e3a4fc4">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("details")]]></dataSourceExpression>
</datasetRun>
<jr:column>
<jr:detailCell>
<frame>
<textField>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</frame>
<frame>
<componentElement>
<jr:table>
<datasetRun subDataset="datasetDetailsHeadBond" uuid="998a8505-69bb-493a-8c3a-5dc7a0e62d42">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("details.head")]]></dataSourceExpression>
</datasetRun>
<jr:column>
<jr:detailCell>
<textField>
<textFieldExpression><![CDATA[$F{isin}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column >
<jr:detailCell >
<textField>
<textFieldExpression><![CDATA[$F{coupon}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</frame>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
</jasperReport>
But, when render a report see only headers (Name 1, Name 2 ...) but no nested data.
How can I fix this, please?
Share Improve this question edited Nov 17, 2024 at 16:25 Alex K 22.9k19 gold badges114 silver badges243 bronze badges asked Nov 16, 2024 at 11:37 EvgeniyEvgeniy 3,3596 gold badges26 silver badges41 bronze badges1 Answer
Reset to default 0The dataset of the nested table should use a path relative to its parent dataset, that is subDataSource("head")
instead of subDataSource("details.head")
<datasetRun subDataset="datasetDetailsHeadBond" uuid="998a8505-69bb-493a-8c3a-5dc7a0e62d42">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("head")]]></dataSourceExpression>
</datasetRun>
I have a JSON like this
{
"details": [
{
"name": "Name 1",
"head": [
{
"isin": "ISIN 1",
"coupon": "Coupon 1"
}
]
},
{
"name": "Name 2",
"head": [
{
"isin": "ISIN 2",
"coupon": "Coupon 2"
}
]
}
]
}
and I want to show a nested table like this
Name 1 |
---|
I have a JSON like this
{
"details": [
{
"name": "Name 1",
"head": [
{
"isin": "ISIN 1",
"coupon": "Coupon 1"
}
]
},
{
"name": "Name 2",
"head": [
{
"isin": "ISIN 2",
"coupon": "Coupon 2"
}
]
}
]
}
and I want to show a nested table like this
Name 1 |
---|
ISIN 1 | Coupon 1 |
---|
Name 2 |
---|
ISIN 2 | Coupon 2 |
---|
My report is here
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport uuid="13bb06fa-a8ce-41f8-b3e4-a094f892f221">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="JSONAdapter"/>
<subDataset name="datasetDetails" uuid="3f8c902f-fffd-48fe-b65f-46e976854490">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="JSONAdapter"/>
<queryString language="json">
<![CDATA[details]]>
</queryString>
<field name="name" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="name"/>
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<field name="head" class="net.sf.jasperreports.engine.data.JsonDataSource">
<property name="net.sf.jasperreports.json.field.expression" value="head"/>
<fieldDescription><![CDATA[head]]></fieldDescription>
</field>
</subDataset>
<subDataset name="datasetDetailsHead" uuid="a91998cc-c1fa-4802-868d-90cb9a24636d">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="JSONAdapter"/>
<queryString language="json">
<![CDATA[details.head]]>
</queryString>
<field name="isin" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="isin"/>
<fieldDescription><![CDATA[isin]]></fieldDescription>
</field>
<field name="coupon" class="java.lang.String">
<property name="net.sf.jasperreports.json.field.expression" value="coupon"/>
<fieldDescription><![CDATA[coupon]]></fieldDescription>
</field>
</subDataset>
<queryString language="JSON">
<![CDATA[]]>
</queryString>
<detail>
<band>
<componentElement>
<jr:table xmlns:jr="http://jasperreports.sourcefe/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourcefe/jasperreports/components http://jasperreports.sourcefe/xsd/components.xsd">
<datasetRun subDataset="datasetDetails" uuid="3ca38bbd-cd5a-44c4-98bb-2e993e3a4fc4">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("details")]]></dataSourceExpression>
</datasetRun>
<jr:column>
<jr:detailCell>
<frame>
<textField>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</frame>
<frame>
<componentElement>
<jr:table>
<datasetRun subDataset="datasetDetailsHeadBond" uuid="998a8505-69bb-493a-8c3a-5dc7a0e62d42">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("details.head")]]></dataSourceExpression>
</datasetRun>
<jr:column>
<jr:detailCell>
<textField>
<textFieldExpression><![CDATA[$F{isin}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column >
<jr:detailCell >
<textField>
<textFieldExpression><![CDATA[$F{coupon}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</frame>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
</jasperReport>
But, when render a report see only headers (Name 1, Name 2 ...) but no nested data.
How can I fix this, please?
Share Improve this question edited Nov 17, 2024 at 16:25 Alex K 22.9k19 gold badges114 silver badges243 bronze badges asked Nov 16, 2024 at 11:37 EvgeniyEvgeniy 3,3596 gold badges26 silver badges41 bronze badges1 Answer
Reset to default 0The dataset of the nested table should use a path relative to its parent dataset, that is subDataSource("head")
instead of subDataSource("details.head")
<datasetRun subDataset="datasetDetailsHeadBond" uuid="998a8505-69bb-493a-8c3a-5dc7a0e62d42">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("head")]]></dataSourceExpression>
</datasetRun>
本文标签: How to render nested tables in Jasper reports from JSON sourceStack Overflow
版权声明:本文标题:How to render nested tables in Jasper reports from JSON source? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745659103a2161779.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论