Jump to content
We've recently updated our Privacy Statement, available here ×

Access Parent Report row from Sub-report


jakubhertyk

Recommended Posts

Hello,

 

I don't think that this is a unique problem to my report but I need to access the current row of the Parent report in the Sub-report.

 

I have a report that generates a Sub-report for every Group Header. This Sub-report uses 12 variables from the current Group Header row of the Parent report. Rather than passing 12 parameters to the Sub-report, I thought that it would be simpler to access the current row of the Parent report where the fields reside. Is there anyway I can accomplish this?

 

Thank you,

 

Jakub :(

Post edited by: jakubhertyk, at: 2007/02/01 22:10

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Hi,

you can write a custom datasource which has access to the parent datasource:

Code:

public class ChildDataSource implements JRDataSource {

private JRDataSource parentDatasource = null;

public ChildDataSource (ParentDataSource parentDatasource) {
super();
this.parentDatasource = parentDatasource;
}

public Object getFieldValue(JRField field) throws JRException {
Object parentObject = parentDatasource.getCurrentRowObject();
....
}

}
Link to comment
Share on other sites

Yes sorry about that (and the late reply). It's just example code, not fully functional. The idea is that you provide a custom datasource for both parent and child. As soon next is being called you store that info in an attribute so the child CustomDataSource can easily access this.

 

Code:

public class CustomDataSource implements JRDataSource {

private CustomDataSource parentDatasource = null;
private Object currentObject = null;

public ChildDataSource (ParentDataSource parentDatasource) {
super();
this.parentDatasource = parentDatasource;
}

public Object getFieldValue(JRField field) throws JRException {
if(parentDatasource != null) {
Object parentObject = parentDatasource.getCurrentRow();
//now use parentObject to get parent info
}
//use currentObject to retrieve info
}

public boolean next() throws JRException {
//process next data
//assign data to currentObject
}

public Object getCurrentObject() {
return currentObject();
}
}

 

hope this helps,

Christiaan

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...