Home
Analytics
Dynamically Set Column Width
RKM
I need to set the column width dynamically. I am using Birt 2.3.2 There is an image like an arrow in the cell and the size needs to increase depending upon the values in the dataset.
I tried setting in the Prepare event but then I am not able to access the dataset values.
Any help is appreciated.
Find more posts tagged with
Comments
mwilliams
Hi RKM,
You should be able to set the width in the onCreate method of the image. You'll be able to access the row data at this point as well. Hope this helps. Let me know if you have any questions.
RKM
Hi Williams,
I appreciate you response. I was doing it on the OnCreate of the Table and was setting the size in inches and pixels as shown in the below code.
if(this.getRowData().getColumnValue("ProtocolTimeout") != null && this.getRowData().getColumnValue("ProtocolTimeout") != 0)
{
if(this.getRowData().getColumnValue("ProtocolActual") != null && this.getRowData().getColumnValue("ProtocolActual") != 0)
{
this.width = ((1/this.getRowData().getColumnValue("ProtocolActual")) * 6.5) + "in";
}
}
else
{
this.width = "6.5in";
}
But I need to do that in % but when I do it on OnCreate it does not change the cell width in %. My report is in Fixed layout because when I export in PDF and Powerpoint the images in the cell start overlapping or are clipped.
I also tried to do it on the on prepare and on Prepare we can set it to % but we do not have hold of data at the event.
Please let me know if you want me to describe more.
Thanks in advance.
mwilliams
RKM,
Is the value you need a value in the dataSet that you could grab in the onFetch, store it in a variable, and then possibly use that where you're needing to have access to this value?
RKM
Hi williams,
yes the value is in the dataset but if I set the value of it in global variable will I be able to access it on the prepare event of the table. I was under the impression that the onfetch will fire after prepare event.
In case we are able to then I would need to run a foor loop on the onfetch and make dynamic variables because every column has images that is dependend on different values. Will that not affect the performance.
I have attached the screenshot of the report that I am producing.the green and black bars you see needs to be adjusted as the days displayed. SO if 1 days as green image should be small and big for black image.
Thanks for response.
mwilliams
RKM,
You are correct. I wasn't thinking of accessing the variable in the onPrepare. My mistake. Your table has a fixed overall width, correct? You're just wanting to change the width of each column or image element?
RKM
Hi Williams,
Yes I have a fixed width, page size is 11 * 8.5 and I need to set the column width because I have given the image as 100%. So If I increase or decrease the width of the column the image will adjust itself and by keeping the width on % basis will export the report in pdf and powerpoint.
Thanks Williams.
mwilliams
RKM,
Are there multiple rows in this table? If so, you won't be able to change the column widths for each row. You'd have to find another approach. If it's only 1 row, I'm not sure why using inches in the onCreate wouldn't work, since you say you're able to do that there. You know the width of the workable area and you'd be able to determine the width in inches for each column based on the percet you find from the data. Maybe I'm not understanding correctly on something still.
Let me know.
RKM
Hi Williams,
When we have a fixed layout for the report and if there are two cells set as 50% percent each. So when I dynamically increase the width of image in inches it gets clipped in the PDF export.
In the attached image the second image shows the full green image whihc is 3.8 inch and in the image above I wanted to set the green as 1.4 inch and Black as 2.4 inch but if you see the black image gets clipped because it tries to extend in the right side instead of using the space on the left.
I am thinking it is because of the fixed layout but if I move to auto layout the report on html comes perfect but when i export it sarts clipping because it tries to adjust the whole report in 11 * 8.5
One more question i have an image which I am setting as the background of the label using the script
this.getStyle().backgroundImage = "\yellow box.png";
I want to set this background from embedded image is there a way to do that
Thanks Williams in advance
mwilliams
Have you tried putting the different images in a single cell and make them "inline"? This way you aren't dealing with cell widths at all.
RKM
When you say Inline does that mean just placing all the images in 1 column or is there a property to set inline.When you please images in a cell they will come one below the other and at a time I will be showing two images side by side one in green and 1 in black as shown in the previous attachment.
Please correct me if I am wrong.
mwilliams
Yes, if you place the images all in a single column, set that column to 100% and resize your "inline" images, it should do what I understand you're wanting, I think.
To get to the inline property, you go to the Advanced section in the property editor, then to Section, and to display and set it to inline. Do this for all images you want to be in a row. That is if you're using the image element and not just using "background image" like you said above.
RKM
Thank you very much for all your help that you provided, it works fine with your last suggestion. I tried for 1 of the columns and it showed according to inch sizes i gave.
But when I export it shows 1 below the other what would be the way to fix that.
mwilliams
I don't see the same in my PDF output when I put two images in the same cell of a table. They stay side by side. Maybe with padding or something you're running out of room in PDF with the fixed page size and it's pushing the second image to the next line.
RKM
yes, williams you were right it works fine now. I adjusted it using a formula and it is exporting fine.
Thanks a lot for all your help.
mwilliams
Great to hear! As always, I'm glad to help where I can. Let us know whenever you have questions!
Good luck!
RKM
Thanks Williams, In Birt 2.3.2 can we set the background image from embedded image. THere is already a post on this but thought to ask you here.