Suppose I have 5 columns in my report: A, B. C, D. E and the user want to choose what columns should be in the report (ex.: A,C,D or A,E or D,E only). Is it possible to do this in iReport?
I know the option “print when expression” but using it I’ll get “holes” in the report (where hidden columns are).
To implement the above what can be done is you cold make use of the overlays . Its explained further.
Suppose initially the column layout is col1,col2,col3,col4,col5
Then seuppose you want to print col1,col2,col4,col5 - col3 goes missing, then col4 should extend and col3 should disaapear completely. , without developing any holes which a print when expression does.
For that you will need to place a column header and data feild too , overlapping column header and data feild on col3 and col4 which will contain the Print When Expressions as per you requirement .The original col3 header and data field would contain print when expression which gets it diappear in the changes scenario and appears for normal scenario
So applying this will completly dissappear the column for the layout. Basically you will have to take care of the print when expressions of the overlay datafield and column headers which would appear when some column goes missing and vice-versa.
Hope the above explantion helps
What I have presented is a suggestion and have included only 3 cols as it would be easy to express. See its completely your choice , like which fields should overlap , as you could decide the priority of the columns based upon the data , see if the extreme left or right columns need to be disappeared , you could just give a simple print when expression to make them disappear , no need to overlap there , because they do not contribute in the layout , or as in don't disturb the design of the data , but if the column to be disappeared lies in between then you have no choice to use , overlapping concept which I have explained in the previous answer.
So , in this overlapping case, yes it is a bit tiring but is the best solution for this case. So need to implement according to the needs. and effectiveness.
Hope it helps.
If you using Jaspersoft 4.7 or later then table component have hide and show column feature.
I did similar kind of report,
I had to provide 22 columns for user selection any combination of columns, If you try to do this manually then it requires to choose user selected values sequence of columns through java and various tabular structure overlapping this makes report complex and slower.
So better way is make a union query where you convert your columns into rows ,
ex: select col1,col2, col3 as KPI name
select col4, col 5, col 6 as KPI name
from tab2 ........................
and you can provide a kpi name as filter to report then use KPI name in crosstab so that depend upon your selection the no. df columns change dynamically.
Try this may be helpful.