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>