Home
Analytics
auto column width?
android272
<p>[BIRT 4.2.2] - Is it possible to auto detect and set a columns width? Currently I am setting the column width like this:</p>
<pre class="_prettyXprint _lang-">
TableHandle table = designFactory.newTableItem("table", cols.size());
table.setWidth("100%");
table.setDataSet(designHandle.findDataSet("ds"));
PropertyHandle computedSet = table.getColumnBindings();
ComputedColumn cs1 = null;
for (int i = 0; i < cols.size(); i++) {
ColumnHandle columnHandle = (ColumnHandle) table.getColumns().get(i);
columnHandle.getWidth().setValue(width.get(i) + "in");
}
</pre>
<p>The problem is that when I am creating the ArrayList "width" I don't always have a width to set it as. So when I don't have a width I just set it to 200 as a place holder. this is ok as now there are no longer columns with a 0 width. I have a json string that dictates how my report needs to be stylized and one of the atributes that get passed along is autoFitWidth = true or false. I would like to use this to determine wither or not I need to have birt automatically set the column width.</p>
<p> </p>
<p>also something strange about the code above is that changing "in" to "px", "pt", "em", "%", "mm" etc. seems to do nothing. no matter what I change it to the columns are the same width.</p>
Find more posts tagged with
Comments
android272
<p>So if you take out the for loop above and don't set the column widths birt will auto calculate and divide the columns evenly. This looks ok but it gives columns with one number a lot of room and squishes paragraphs of text into small columns. So now I am trying to determine the length of the header and the cells to evaluate how wide the columns should be.</p>
<p> </p>
<p>So I started messing with the widths to see how small the column can get before it brakes to the next line. I found that each character is worth 10 units long. I say units because birt does seem not care if I say 10px or 10in they are the same to birt(actually birt does care if you mix units. So don't mix units unless you want a column to actually be 25% of the page). Below is an updated for loop that calculates the width based upon the header length, multiplies it by 10 to get the right width, and adds 20 to for padding.</p>
<pre class="_prettyXprint _lang-">
for (int i = 0; i < cols.size(); i++) {
ColumnHandle columnHandle = (ColumnHandle) table.getColumns().get(i);
columnHandle.getWidth().setValue(cols.get(1).length() * 10 + 20 + "px");
} </pre>
<p>This stackoverflow answer was a big help even though It talks about the designer. It talks about how birt determines the column widths.</p>
<p><a data-ipb='nomediaparse' href='
http://stackoverflow.com/questions/24622812/birt-how-to-autofit-width-of-last-column-when-adjusting-cell-width'>http://stackoverflow.com/questions/24622812/birt-how-to-autofit-width-of-last-column-when-adjusting-cell-width</a></p>
;
<p> </p>
<p>Now I need to determine the length of each cell and add to that. does anyone know if you can modify the column widths after the design phase? </p>
android272
<p>Oh I forgot to say if you do this for all columns then Birt will default to back to calculating the widths and divide them evenly.</p>
JFreeman
<p>Are you still needing assistance with this one?</p>
android272
<p>So I got widths to work and everything looks ok. but what we would like to do is go through each cell, evaluate its values width, compare it with the headers width and if the cells are bigger then set the column width.</p>
<p> </p>
<p>I can set the column width in my onCreate() method. Now I just need to someone check the cells width and determine if I need to reset the column width.</p>
JFreeman
<p>To verify I am understanding correctly, you are wanting to iterate through the cells in your table's detail row, compare their width to the width of the same columns cell in the header row and if the detail row cell is bigger you want to adjust the column width accordingly?</p>
android272
<p>Yes this is exactly what I want to do. Except for text. currently we have it set all widths based upon the length of the header. Setting every column width will actually distribute the columns evenly because there is all this extra room at the end of the table, so birt decides to distribute them instead of giving the last column the extra. This looks fine till you look at the data, two character data will take up a loot a room and paragraphs of data will get squashed.</p>
<p> </p>
<p>So to add even more complexity to this problem we would like to check weather the cell contains a string and clear the width of that column. this way once every other cell has their widths set birt will allocate the appropriate width based upon what room is left. </p>