Dynamic table with auto column width
I wish to know the best way to approach my problem.
I have a dynamic query that is set by the user at runtime. I wish to then print this query in a table in a Fast report.
I have had a look at the PrintTable demo but unfortunately it doesnt perform exactly as i require.
My query will consist of at most 6 fields. I would like to print the table in the report, but auto fit the columns based on the best fit method.
That is, based on the maximum text width of the each column, fit the table EXACTLY within 1 page (i.e. no overlap to the left or right).
So if that query has only 4 fields the stretch them accordingly to fit the width of 1 page. Similarly with a query of 5 or 6 fields.
Using the CrossView, i can set a maximum width of each column, and also autofit the contents, but if all columns are large, then the crossview spills over to the following page.
So is there any way where a Crossview/Master band can be created at runtime, and then according to the number of fields in the dataset, perform a 'BEST FIT' algorithm to adjust the column widths so they fit nicely within the width of the page?
Thanks
I have a dynamic query that is set by the user at runtime. I wish to then print this query in a table in a Fast report.
I have had a look at the PrintTable demo but unfortunately it doesnt perform exactly as i require.
My query will consist of at most 6 fields. I would like to print the table in the report, but auto fit the columns based on the best fit method.
That is, based on the maximum text width of the each column, fit the table EXACTLY within 1 page (i.e. no overlap to the left or right).
So if that query has only 4 fields the stretch them accordingly to fit the width of 1 page. Similarly with a query of 5 or 6 fields.
Using the CrossView, i can set a maximum width of each column, and also autofit the contents, but if all columns are large, then the crossview spills over to the following page.
So is there any way where a Crossview/Master band can be created at runtime, and then according to the number of fields in the dataset, perform a 'BEST FIT' algorithm to adjust the column widths so they fit nicely within the width of the page?
Thanks
Comments
Thanks for the reply but i dont hink it is as easy as that.
Firstly, I am unsure of how i can link a dynamically created crossview with a pascal script event handler in code (in the ReportBeforePrint event).
Secondly, the OnCalcWidth refers to the width of the column which generated the event, and it doesnt pass any references to the other columns.
my current code for populating the crossview looks like this:
procedure rptBeforePrint(s : TfrxReportComponent);
if c is TfrxCrossView then
begin
Cross := TfrxCrossView©;
qryDynamic.Close;
qryDynamic.SQL.Clear;
qryDynamic.SQL.Add(SQL);
qryDynamic.Open;
i := 0;
while not qryDynamic.Eof do
begin
for j := 0 to qryDynamic.Fields.Count - 1 do
Cross.AddValue(, [qryDynamic.Fields[j].DisplayLabel], [qryDynamic.Fields[j].AsString]);
qryDynamic.Next;
Inc(i);
end;
end;
The TFrxCrossView doesnt expose any column width or columns property.