Dynamic table columns - Distribute columns to table's width

Hello,


I'm migrating a HTML report to FastReport.Net. The report has dynamic columns.


The Table is definde as follows:



The column's 'ASCII Position', 'Fieldname' and 'XML Tag' depend on flags in the data. I Manged to hide the columns. But I didn't get the equivalent of or anything near the current HTML-report, because the column is simply not painted.


I would like to achieve the behavior as in HTML, where I set the Table to a certain width and the columns have a percentual width and spread over the given fixed width for the table.


In my report, the result looks as follows:


What I try to achieve is something like the following:

  • set the table.width to 17,5 cm
  • set the column.width for 'Name' to something like '30%'
  • set the column.width for 'Beschreibung' to something like '70%'
  • set the other visible columns to thier fixed witdt (e.g. 1,5 cm)

I would expect to have always a tablewidth of 17,5 cm. Further I would expect that the "dynamic" width colums calculate thier width like this: table.width - ('all fixed width') * column.width (e.g. 30%)


Is there a simple way to achieve this?


Best Regards

Marc

Comments

  • Hello!

    The TableObject in FastReport .NET does not have built-in HTML/CSS automatic recalculation of column widths when adjacent columns are hidden. However, the desired percentage distribution (30% / 70% of the remaining page width) can be easily set in the Table1_BeforePrint event (or ManualBuild):

    float pageUsablePx = 17.5f * Units.Centimeters;
    float fixedPx = 0f;
    if (colAsciiVisible) fixedPx += 1.5f * Units.Centimeters;
    if (colFieldVisible) fixedPx += 1.5f * Units.Centimeters;
    if (colXmlVisible) fixedPx += 1.5f * Units.Centimeters;
    
    float remainPx = pageUsablePx - fixedPx;
    Table1.Columns[0].Width = remainPx * 0.30f; // Name (30%)
    Table1.Columns[1].Width = remainPx * 0.70f; // Description (70%)
    
This discussion has been closed.