Home
Analytics
Birst Script : setting column property (width)
fastlock1
I am trying to create a kind of 'tree' using a table.
A
.... B
.........B1
.........B2
.... C
the structure is a table with a grid in each row.
The grid has a left cell for indent and a right cell for the value.
I can not have only one cell because I also need an image (which is not described here to avoid complexity).
1/ I manage to get it as a table in BIRT with all the values.
2/ I also can compute the left part for indentation : number of steps or a string with the right nuimber of whitespaces (here '.')
3/ I set the left
-->
This is working FINE in HTML reports because an HTML table even if its content is 5px for example always sets its width to suits the text content.
HOWEVER this is not te case in Powerpoint or PDF .
The Cell is 5px with a 100px text inside which is ugly.
**************************
Ok I tried to create a SCRIPT on the column ... But the 'column' is not an object with methods in the script area like the row, the cell or the "data" label inside.
I tried to get it from the "data" label and from the row and from te table but I have no API to set the column property (SET Column WIDTH)
I can get the with like this :
var wIndex = 10;
if ((this.getRowData().getColumnCount() > 1)
&& (this.getRowData().getColumnValue(1) != null))
wIndex = this.getRowData().getColumnValue(1).toString().length();
then I "just" need to so something like
this.getColumn(1).width=wIndex+"px"
or
this.columns[1].width=wIndex+"px"
or something like this.setProperty xxxx
Found nothing clear in the documentation, neither in google search.
Any Idea since API documentation is really unusable for scripting with efficiency.
best regards
Find more posts tagged with
Comments
fastlock1
for setting the columns.
On 'tables' we have something like
this.getColumns().get(0)
but I need to set each with on a line per line basis : ths is set the width of the GRID inside the table cell.
best regards
mwilliams
Hi fastlock1,
So, you're trying to set the width of the column on every row? Can you recreate this issue with the sample database and attach the report in here so I can see exactly what you're doing?
fastlock1
Thanks for your answer, unfortunately since I have to deliver something by the end of this week I have little time to reproduce it against a demo db but here are in attachment some screencaps + rptdesign
1 : the original tree (not in a report this is JSP / html based)
2 : the screencap of the design : a table with one column to repeat for each line the content, then a grid in the unique cell of each line to line up the content. First column of the GRID is automatically indented (size vary)
3 : result as HTML is quite ok even if could be improved
4 : result in PPT is n ot working (overlaps of columns content, not indented)
******************
I tried something else : trying to get out Javascript mode that way :
A] write a javaclass like this
package com.atpi.view.report;
import org.eclipse.birt.report.engine.script.internal.instance.BirtGridHelper;
public class Birt2Java {
public static void computeWidth(Object param)
{
System.out.println(" object "+param);
BirtGridHelper.computeWidth(param);
}
}
B] use this in the javascript for the cell of the first column of the GRID
importPackage(Packages.com.atpi.view.report);
try
{
Birt2Java.computeWidth(this.getParent().getParent().getParent());
} catch (Oops)
{
this.setDisplayValue(Oops.message);
}
C] This Works in the way I can get the Java object which is
a org.eclipse.birt.report.engine.script.internal.instance.GridInstance
and this time I have the full API + debugger in eclipse !
Unfortunately the column is inside the object in a protected member 'content' with no getContent() accessor ... the object inside is an instance of org.eclipse.birt.report.engine.content.ITableContent
I tried to subclass it to get to the columns :
package org.eclipse.birt.report.engine.script.internal.instance;
import org.eclipse.birt.report.engine.api.script.element.IColumn;
import org.eclipse.birt.report.engine.content.ITableContent;
import org.eclipse.birt.report.engine.script.internal.instance.GridInstance;
public class BirtGridHelper extends GridInstance {
GridInstance grid;
public BirtGridHelper(GridInstance gridI) {
super(null, null);
grid = gridI;
// TODO Auto-generated constructor stub
}
public static void computeWidth(Object param)
{
System.out.println(" object "+param);
GridInstance gridI = (GridInstance)param;
BirtGridHelper helper = new BirtGridHelper(gridI);
helper.computeWidth();
}
public void computeWidth()
{
ITableContent gridTableContent = (ITableContent)grid.content;
IColumn col = (IColumn)gridTableContent.getColumn(0);
int jj=0;
}
}
D] this above compiles well, and should work : unfortunatrely I get a ClassNotFoundexception even if the .class is inside my package (classLoader issue ???) or signed jar issue ?
In another part of the code (not from the script) I manage to instantiate BirtGridHelper but in that classloader this is the GridInstance class wich is not found.
**********************************************
Here is where I am but I guess I will have to giveup this for a while since I have other feature to code by friday and spent too much time on that part.
Best regards