i had need to show crosstabHeaderCell columns dynamically from string array. this is a json
{
"header": {
"columnName": [
"Product Store1",
"location"
],
"values": [{
"purchase": {
"name": "bags",
"location": "MainMarket "
},
"weekSpend": [{
"weekStartDate": 20181105,
"spend": 100
},
{
"weekStartDate": 20181112,
"spend": 200
}
]
},
{
"purchase": {
"name": "shoes",
"location": "MainMarket "
},
"weekSpend": [{
"weekStartDate": 20181105,
"spend": 100
},
{
"weekStartDate": 20181112,
"spend": 200
}
]
}
]
}
I want to show crosstabHeaderCell from list of values of array columnName in cross tab. from the above json I am able to iterate and show product name and location as rows and weekSpend as column with data set of crosstab as
<crosstabDataset isDataPreSorted="true">
<dataset>
<datasetRun subDataset="crossTabDataSet" uuid="e7b27508-8a48-4785-a48e-c646249df9a9">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonQLDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("..values(@size > 0)..weekSpend.*")]]></dataSourceExpression>
</datasetRun>
</dataset>
</crosstabDataset>
when i specify list component for crosstabHeaderCell as below i am getting error parameter REPORT_DATA_SOURCE not found.
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Horizontal" ignoreWidth="true">
<datasetRun subDataset="listcol" uuid="a13d0691-5b9e-4d9f-aaa0-9d0ff0b67b78">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonQLDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("$.columnName.*")]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="100">
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="99c3d5fe-9f90-4efc-bdab-4371eee17d54"/>
<textFieldExpression><![CDATA[$F{namecol}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
the dataset listcol is defined as
<subDataset name="listcol" uuid="2630f2ff-b912-4f05-8189-7a5d47eada9e">
<field name="namecol" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="[0]"/>
</field>
</subDataset>
how can a i refer to list of values from crosstab data set. why does list fail with parameter not found exception for REPORT_DATA_SOURCE. can we set the REPORT_DATA_SOURCE value from crosstab dataset to be used by inner dataset.
if i remove REPORT_DATA_SOURCE jr:list and use querystring listcol as $.columnName.*. i get blank in crosstabHeaderCell
Thanks Anjana,
You need to make use of
crosstabParameter
s in order to pass data from the enclosing report, like so:with the following output: