Skip to content

Report Engine Automatic datasource context keys

MACK Mathieu edited this page Oct 16, 2017 · 1 revision

When you bind a DataSource to a ForEach, a ForEachPage or a Table, the report engine can automatically add some keys that you can use to show or hide some elements.

To do it, you must :

  • Set a value on the field "AutoContextAddItemsPrefix" to the ForEach, ForeachPage or Table element.
  • Set some ShowKey values with the prefix.

List of created keys :

  • #AutoContextAddItemsPrefix_ItemType_IsFirstItem# Contains a BooleanModel that is true when you are on the first item in the DataSource.
  • #AutoContextAddItemsPrefix_ItemType_IsLastItem# Contains a BooleanModel that is true when you are on the last item in the DataSource.
  • #AutoContextAddItemsPrefix_ItemType_IndexBaseZero# Contains a StringModel that contains the index of the current element, base on zero index. 0, 1, ...
  • #AutoContextAddItemsPrefix_ItemType_IndexBaseOne# Contains a StringModel that contains the index of the current element, base on one index. 1, 2, ... Note : You must replace ItemType by 'ForEach', 'ForEachPage' or 'TableRow'. Ex : #AutoContextAddItemsPrefix_Table_IsFirstItem#

Example :

var tableDataSourceWithPrefix = new Table()
{
TableWidth = new TableWidthModel() { Width = "5000", Type = TableWidthUnitValues.Pct },
ColsWidth = new int[2] { 750, 4250 },
Borders = new Word.ReportEngine.Models.Attributes.BorderModel()
{
    BorderPositions = (Word.ReportEngine.Models.Attributes.BorderPositions)63,
    BorderColor = "328864",
    BorderWidth = 20,
},
DataSourceKey = "#DatasourcePrefix#",
AutoContextAddItemsPrefix = "CustomDataSourcePrefix",
RowModel = new Row()
{
    Cells = new List<Cell>()
    {
        new Cell()
        {
            Shading = "FFA0FF",
            ChildElements = new List<BaseElement>()
            {
                new Label() { Text = "Item Datasource (0 index) #CustomDataSourcePrefix_TableRow_IndexBaseZero# - ",
                                ShowKey = "#CustomDataSourcePrefix_TableRow_IsFirstItem#" },
                new Label() { Text = "#Cell1#" }
            }
        },
        new Cell()
        {
            ChildElements = new List<BaseElement>()
            {
                new Label() { Text = "Item Datasource (1 index) #CustomDataSourcePrefix_TableRow_IndexBaseOne# - ",
                                ShowKey = "#CustomDataSourcePrefix_TableRow_IsLastItem#" },
                new Label() { Text = "#Cell2#" }
            }
        }
    }
}
};

On this table, I hide some elements if you are on the first or last line.

Clone this wiki locally