Itext7 modify table width - itext7

In java itext5 there is function table.setWidths() hence we can modify column widths on fly.
In itext7 table.setWidths() is not there and new Table(colwidths) have to pass in constructor this is fixed and cannot modyify on fly.Please let me know the procedure to modify table widths like itext5.
Itext5
Table table = new Table(3);
float[] widths=new float[3.0,4.0,5.0];
table.setWidths(widths);
what is the above code itext7?

Related

Xamarin forms - Change grid row visibility dynamically

I want to change a specific row visibility inside of a grid named "myGrid" given an index dynamically.
I thought first to get the specific row that I want use:
var row = Grid.GetRow(myGrid.Children[index]);
and then , to change the IsVisible attribute of 'row' like this:
row.IsVisible = false;
Unfortunately the second line of code Isn't legal...
I don't want to bind 'IsVisible' attribute of each row. It seem to me unnecessary work.
Any suggestion to solving this issue will be appreciate!!
I think your best bet is to bind the IsVisible property of each control in the row to a single property in your view model. Then all you have to do is change the value of your view model property to false and the whole row will be hidden.
Cause:
GetRow returns an int value.So you can't set the property like IsVisible
Solution:
You can set the rowHeight as 0 if you want to hide the specific row.
var row = myGrid.RowDefinitions[index];
row.Height = 0;
As others said, you are trying to change the visibility of an index (That is definitely wrong).
You cannot get the row of a Grid and set its visibility. Instead, you should set the visibility of the view inside the row.
But you should note that by doing so you may see an empty space inside the Grid if you have specified a fixed height or even star sizing for that row height.
It is better to set row height to Auto. By doing this, when the view inside that row is invisible, the height of the row decreases to 0.

Fit columns to content in handsontable

I am new to handsontable, and I can not achieve a goal as simple as to have the columns width as long as the content of the cells. Even if I have space enough in handsontable parent to display the full content of the table, some columns overlap the content of some cells.
I do not want to stretch the table to its parent. Just to show the full table contents (as I have space enough).
Update
The answer of fap is right.
I have realized the problem does not come from the basic definition of the table but for the definition of a renderer do on cells.
cells: function (row, col, prop) {
var cellProperties = {};
if (row === 0) {
cellProperties.renderer = firstRowRenderer;
}
return cellProperties;
}
function firstRowRenderer(instance, td, row, col, prop, value, cellProperties) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
td.style.fontWeight = 'bold';
td.style.color = 'green';
td.style.background = '#CEC';
}
It is after the renderer is applied when the content does not fit into handsontable cells and it does not resize. This is the real problem I am facing.
Just don't specify any width for the table and/or columns. Handsontable will size the columns depending of the longest value there is in their respective cells.
See this simple example.
Note that if you edit the values, the column resize dynamically.
But what if you have a value that expand the column width so much that your table is wider than your screen ? Well, if you don't really want that (and I assume that you don't otherwise what's the point of delimiting your columns and/or your table in the first place ?), you can use the option preventOverflow :
preventOverflow: 'horizontal',
As you can see in this example, it will automatically create a navigate bar that prevent your table to go off screen but still size the columns in order to see all your data.

iText: Different table rows with different cell/column widths

How to create with Java a table with three rows as follows:
First row has one cell 100% entire table width
Second row has first from the left cell width 50mm, and second 20mm and third 30mm which in total is 100% of table width
Third row has first from the left cell width 30mm, and second 50mm and third 10mm which in total is 90% of table width
How would the code from the iText look like?
So you want to use iText to create a table that looks like this:
The PDF in the screen shot was created using the TableMeasurements example. The resulting PDF can also be downloaded for inspection: table_measurements.pdf
The first thing that jumps to the eye when looking at this screen shot is the fact that the table doesn't look "complete". This means that we will have to complete the table the way I already explained on SO yesterday (and many times before that): Why the 2nd row of table won't be written? (which was actually a duplicate of How to generate pdf if our column less than the declared table column and ItextSharp, number of Cells not dividable by the length of the row and Odd Numbered Cell Not Added To Pdf and PdfTable: last cell is not visible and ...)
In the comment section, I was asked:
How can I complete row with cells with no border?
I answered:
Use table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
Note that PdfPCell.NO_BORDER also works as PdfPCell extends the Rectangle class.
In your case, we'd have something like this:
public void createPdf(String dest) throws IOException, DocumentException {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(dest));
document.open();
PdfPTable table = new PdfPTable(10);
table.setTotalWidth(Utilities.millimetersToPoints(100));
table.setLockedWidth(true);
table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
table.addCell(getCell(10));
table.addCell(getCell(5));
table.addCell(getCell(3));
table.addCell(getCell(2));
table.addCell(getCell(3));
table.addCell(getCell(5));
table.addCell(getCell(1));
table.completeRow();
document.add(table);
document.close();
}
To make the example more realistic, I created a table with an exact width of 100 mm. For the width to be acknowledged, I lock the width. As already explained, I make sure that default cells have no border. After adding all the cells with the different widths (10 cm, 5 cm, 3 cm, 2 cm, 3 cm, 5 cm, 1 cm), I complete the row.
What does the getCell() method look like, you might wonder. This was already answered by Amedee in the comments (which for some reason you ignored):
private PdfPCell getCell(int cm) {
PdfPCell cell = new PdfPCell();
cell.setColspan(cm);
cell.setUseAscender(true);
cell.setUseDescender(true);
Paragraph p = new Paragraph(
String.format("%smm", 10 * cm),
new Font(Font.FontFamily.HELVETICA, 8));
p.setAlignment(Element.ALIGN_CENTER);
cell.addElement(p);
return cell;
}
We create a PdfPCell and we set the colspan to reflect the width in cm. I added some more fancy stuff. I didn't use any functionality in this example that isn't explained on the official web site or on StackOverflow.
For more rowspan and colspan examples, please take a look at the Colspan and rowspan section in the official documentation.

Get value of column in dataset in javascript

I would like to draw dynamic vertical marker line in my chart. Position of marker is available in dataset named ml_data in column ml_position. This is a dataset with one row and one column only. Is there a way how I can get value of ml_position in javascript? Currently I have the following working example:
function beforeDrawMarkerLine(axis, markerLine, icsc)
{
importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
importPackage(Packages.org.eclipse.birt.chart.model.component.impl);
var ml_value = 20;
markerLine.setValue(NumberDataElementImpl.create(ml_value)) ;
}
The value is currently fixed (20). I would like to assign value of ml_position to ml_value.
My working solution:
Create global variable "mpos" and put your chart into simple table with one row a one column. Assign dataset with ml_position to table. This is important for executing dataset onFetch script before rendering chart. Finally set following scripts:
Dataset onFetch script:
reportContext.setPersistentGlobalVariable("mpos",row["ml_position"].toString());
Chart onRender script:
function beforeDrawMarkerLine(axis, markerLine, icsc)
{
importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
importPackage(Packages.org.eclipse.birt.chart.model.component.impl);
var ci = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("mpos");
markerLine.setValue(NumberDataElementImpl.create(ci)) ;
}

birt report generic style for all rows in table

I am trying to create a generic style for all rows in my data table. I have been looking around and there seems to be a function I can use named rownum.
I tired to create the style like this...
row["__rownum"] Less than 0
then colour = Red
But this is not right. Can someone tell me the right way to do this so I can apply the style to multiple cells in my table.
Also where can i find documentation on what sort of functions like this are available?
thanks
I know two ways how you can specify conditional styles in BIRT:
You can write an "onRender" eventHandler (either in Java or JavaScript) for your row. In JavaScript it could looks as follow:
if (row["__rownum"] % 2 == 0) {
this.getStyle().backgroundColor = "red";
} else {
this.getStyle().color = "red";
}
Or create a new BIRT style with a highlight-rule like follows:
row["__rownum"] % 2 equals to 0 then
Set Color or whatever or apply another style
Instead of creating a new style, that you will have to assign to target elements, you can also modify one of the predefined styles, if you find a one matching your targets.
Both EventHandler and Styles can be assigned to various element: Cells, Rows, Tables, Report...
Links you may find helpful:
https://www.eclipse.org/birt/phoenix/deploy/reportScripting.php
http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.birt.doc.isv%2Fmodel%2Fapi%2Forg%2Feclipse%2Fbirt%2Freport%2Fmodel%2Fapi%2FElementFactory.html
BIRT: Alternating row Color in a table group

Resources