The Table element is a grid-type element that allows you to construct a grid that relies on rows and cells rather than rows and columns, such as the Grid element. The Table element doesn't have specific columns that determine the width of cells like the Grid element.
The Table element allows you to customize the width of every cell if needed, giving you absolute control of how your data is presented. The two drawbacks to this grid design have to do with column and row spanning. You have to "fake" a column span by doubling the width of a particular cell, and you cannot span rows.
Being a member of the pattern content family, you can modify the style of different Table elements by applying patterns at different levels of the table:
The Table element also contains Header, Footer, and Divider elements. These elements consist of only one row. These elements also behave in the same manner as the Header, Footer, and Divider elements of the Band element. Headers display at the top of the table on every page or only the first page, depending on the Repeat property; the same goes for footers, but applying to the last page. Dividers display at the end of every page where the table spills over to the next page.
The following code creates a table with three rows, including a header and footer. The first and third rows simulate a column span by manipulating the width of specific cells to be twice the width of the standard cell width. The middle row demonstrates the Table element’s ability to create completely custom rows by modifying the cell width to each be one-third the width of the table.
Create the table and cell patterns.
In C#:
using Infragistics.Documents.Reports.Report;
.
.
.
// Create a new pattern for the table as a whole.
Infragistics.Documents.Reports.Report.Table.TablePattern tablePattern =
new Infragistics.Documents.Reports.Report.Table.TablePattern();
tablePattern.Background = new Background(Brushes.LightSteelBlue);
tablePattern.Borders = new Borders(new Pen(new Color(0, 0, 0)), 5);
// Create a new pattern for the cells.
Infragistics.Documents.Reports.Report.Table.CellPattern tableCellPattern =
new Infragistics.Documents.Reports.Report.Table.TableCellPattern();
tableCellPattern.Borders = new Borders(new Pen(new Color(0, 0, 0)));
tableCellPattern.Background = new Background(Brushes.LightSteelBlue);
tableCellPattern.Paddings = new Paddings(5, 10);
Create the table and apply the table pattern.
In C#:
// Create the table and apply the table pattern.
Infragistics.Documents.Reports.Report.Table.ITable table = section1.AddTable();
table.Width = new RelativeWidth(100);
table.ApplyPattern(tablePattern);
Create the header and footer.
In C#:
// Create the table header.
Infragistics.Documents.Reports.Report.Table.ITableHeader tableHeader =
table.Header;
Infragistics.Documents.Reports.Report.Table.ITableCell tableHeaderCell =
tableHeader.AddCell();
tableCellPattern.Apply(tableHeaderCell);
tableHeaderCell.AddQuickText("Table Header");
// Create the table footer.
Infragistics.Documents.Reports.Report.Table.ITableFooter tableFooter =
table.Footer;
Infragistics.Documents.Reports.Report.Table.ITableCell tableFooterCell =
tableFooter.AddCell();
tableCellPattern.Apply(tableFooterCell);
tableFooterCell.AddQuickText("Table Footer");
Create the first row.
In C#:
Infragistics.Documents.Reports.Report.Table.ITableRow tableRow;
Infragistics.Documents.Reports.Report.Table.ITableCell tableCell;
tableRow = table.AddRow();
tableCell = tableRow.AddCell();
tableCell.Width = new RelativeWidth(100);
tableCellPattern.Apply(tableCell);
tableCell.Background = new Background(Brushes.LightSlateGray);
IText tableCellText = tableCell.AddText();
tableCellText.Alignment =
new TextAlignment(Alignment.Center, Alignment.Middle);
tableCellText.AddContent("'Column' Span 1");
tableCell = tableRow.AddCell();
tableCell.Width = new RelativeWidth(50);
tableCellPattern.Apply(tableCell);
tableCellText = tableCell.AddText();
tableCellText.Alignment =
new TextAlignment(Alignment.Center, Alignment.Middle);
tableCellText.AddContent("Cell 2");
tableCell = tableRow.AddCell();
tableCell.Width = new RelativeWidth(50);
tableCellPattern.Apply(tableCell);
tableCellText = tableCell.AddText();
tableCellText.Alignment =
new TextAlignment(Alignment.Center, Alignment.Middle);
tableCellText.AddContent("Cell 3");
Create the second row.
In C#:
tableRow = table.AddRow();
tableCell = tableRow.AddCell();
tableCell.Width = new RelativeWidth(33);
tableCellPattern.Apply(tableCell);
tableCellText = tableCell.AddText();
tableCellText.Alignment =
new TextAlignment(Alignment.Center, Alignment.Middle);
tableCellText.AddContent("33%");
tableCell = tableRow.AddCell();
tableCell.Width = new RelativeWidth(33);
tableCellPattern.Apply(tableCell);
tableCellText = tableCell.AddText();
tableCellText.Alignment =
new TextAlignment(Alignment.Center, Alignment.Middle);
tableCellText.AddContent("33%");
tableCell = tableRow.AddCell();
tableCell.Width = new RelativeWidth(33);
tableCellPattern.Apply(tableCell);
tableCellText = tableCell.AddText();
tableCellText.Alignment =
new TextAlignment(Alignment.Center, Alignment.Middle);
tableCellText.AddContent("33%");
Create the third row.
In C#:
tableRow = table.AddRow();
tableCell = tableRow.AddCell();
tableCell.Width = new RelativeWidth(50);
ableCellPattern.Apply(tableCell);
tableCellText = tableCell.AddText();
tableCellText.Alignment =
new TextAlignment(Alignment.Center, Alignment.Middle);
tableCellText.AddContent("Cell 1");
tableCell = tableRow.AddCell();
tableCell.Width = new RelativeWidth(50);
tableCellPattern.Apply(tableCell);
tableCellText = tableCell.AddText();
tableCellText.Alignment =
new TextAlignment(Alignment.Center, Alignment.Middle);
tableCellText.AddContent("Cell 2");
tableCell = tableRow.AddCell();
tableCell.Width = new RelativeWidth(100);
tableCellPattern.Apply(tableCell);
tableCell.Background = new Background(Brushes.LightSlateGray);
tableCellText = tableCell.AddText();
tableCellText.Alignment =
new TextAlignment(Alignment.Center, Alignment.Middle);
tableCellText.AddContent("'Column' Span 2");
View on GitHub