Yesterday I realised that a lot of people were having troubles using the addGrid method in its current state, cause it was not flexible enough for everybody.
I just commited a new release of the 0.1.4.8 release in the AlivePDF SVN, here is how it works now.
First use is the following, you create a Grid and pass some data, you don't specify any width, alignement or even field or header text :
// create a Grid object as usual
var grid:Grid =
new Grid
( dp.
toArray(),
200,
120,
new RGBColor
(0x666666
),
new RGBColor
(0xCCCCCC
),
new RGBColor
(0),
true,
new RGBColor
( 0x0
), Joint.
MITER );
// pass the grid
myPDF.addGrid(grid);
What you will get is a grid with each column with a default width and each column field name as the header text.
Now here comes the good part :
// create columns with header text (here in French), field name, column width, header text and cell alignment
var gridColumnAge:GridColumn =
new GridColumn
("Age",
"age",
20,
Align.
LEFT,
Align.
LEFT);
var gridColumnFirstName:GridColumn =
new GridColumn
("Prénom",
"firstName",
20,
Align.
LEFT,
Align.
LEFT);
var gridColumnLastName:GridColumn =
new GridColumn
("Nom",
"lastName",
40,
Align.
LEFT,
Align.
LEFT);
var gridColumnEmail:GridColumn =
new GridColumn
("E-Mail",
"email",
45,
Align.
LEFT,
Align.
LEFT);
var gridColumnCity:GridColumn =
new GridColumn
("Ville",
"city",
40,
Align.
LEFT,
Align.
LEFT);
// create a columns Array
// it determines the order shown in the PDF
var columns:Array = new Array ( gridColumnLastName, gridColumnFirstName, gridColumnAge, gridColumnEmail, gridColumnCity );
// create a Grid object as usual
var grid:Grid = new Grid ( dp.toArray(), 200, 120, new RGBColor (0x666666), new RGBColor (0xCCCCCC), new RGBColor (0), true, new RGBColor ( 0x0 ), Joint.MITER );
// pass the columns
grid.columns = columns;
// pass the grid
myPDF.addGrid(grid);
As you can see, a new GridColumn class is added, which allows you to represent physically in ActionScript each column, with a specific text header, a field, a width and alignment.
Keep in mind that if you use the columns property of the Grid class, it also allows you to filter some fields so that they do not appear in the grid. Let's say you do not want the email to show, you will simply modify the columns array this way :
var columns:Array = new Array ( gridColumnLastName, gridColumnFirstName, gridColumnAge, gridColumnCity );
Let's say you want to change the order of the columns in the grid :
var columns:Array = new Array ( gridColumnFirstName, gridColumnLastName, gridColumnCity, gridColumnAge );
Can you guys download this latest version and test it and let me know if it works nicely for you ? Thanks !