3.9 Tablix 3

The following is an example RDL definition of a Tablix element used to lay out data in nested rows, repeating columns, and a sibling column. The tablix uses text boxes within cells to format and display the data. This layout encompasses the functionality of the Matrix element in schema versions prior to RDL 2008/01. The data is fetched from the Microsoft Adventure Works example database. The top of the rendered definition is shown in the following illustration.

Tablix example 3

Figure 19: Tablix example 3

The Tablix element has its Tablix.Name attribute set to "Tablix3".

            
 s<Tablix Name="Tablix3">

The column hierarchy is defining two dynamic columns. The first is colored aqua and the second is colored pink.

     <TablixColumnHierarchy>

The first dynamic column is grouping on SalesPerson and contains two static columns within the same hierarchy. All text boxes within the first tablix member are colored aqua. The dynamic column and the static columns within it are repeated for each SalesPerson in the data.

       <TablixMembers>
         <TablixMember>
           <Group Name="SalesPerson">
             <GroupExpressions>
               <GroupExpression>=Fields!SalesPerson.Value</GroupExpression>
             </GroupExpressions>
           </Group>
           <TablixHeader>

Because the TablixHeader element is within the column hierarchy, the RdlSize value represents row height.

             <Size>0.48438in</Size>
             <CellContents>
               <Textbox Name="SalesPerson">
                 <CanGrow>true</CanGrow>
                 <KeepTogether>true</KeepTogether>
                 <Paragraphs>
                   <Paragraph>
                     <TextRuns>
                       <TextRun>
                         <Value>=Fields!SalesPerson.Value</Value>
                         <Style>
                           <FontSize>12pt</FontSize>
                         </Style>
                       </TextRun>
                     </TextRuns>
                     <Style>
                       <TextAlign>Center</TextAlign>
                     </Style>
                   </Paragraph>
                 </Paragraphs>
                 <Style>
                   <Border>
                     <Color>LightGrey</Color>
                     <Style>Solid</Style>
                   </Border>
                   <BackgroundColor>Aqua</BackgroundColor>
                 </Style>
               </Textbox>
             </CellContents>
           </TablixHeader>

The first nested TablixMember defines a nested column for List Price under each SalesPerson.

           <TablixMembers>
             <TablixMember>
               <TablixHeader>
                 <Size>0.45833in</Size>
                 <CellContents>
                   <Textbox Name="Textbox8">
                     <CanGrow>true</CanGrow>
                     <KeepTogether>true</KeepTogether>
                     <Paragraphs>
                       <Paragraph>
                         <TextRuns>
                           <TextRun>
                             <Value>List Price</Value>
                             <Style>
                               <FontWeight>Bold</FontWeight>
                             </Style>
                           </TextRun>
                         </TextRuns>
                         <Style>
                           <TextAlign>Right</TextAlign>
                         </Style>
                       </Paragraph>
                     </Paragraphs>
                     <Style>
                       <Border>
                         <Color>LightGrey</Color>
                         <Style>Solid</Style>
                       </Border>
                       <BackgroundColor>Aqua</BackgroundColor>
                     </Style>
                   </Textbox>
                 </CellContents>
               </TablixHeader>
             </TablixMember>

The second nested tablix member defines a nested column for Standard Cost under each SalesPerson.

             <TablixMember>
               <TablixHeader>
                 <Size>0.45833in</Size>
                 <CellContents>
                   <Textbox Name="Textbox9">
                     <CanGrow>true</CanGrow>
                     <KeepTogether>true</KeepTogether>
                     <Paragraphs>
                       <Paragraph>
                         <TextRuns>
                           <TextRun>
                             <Value>Standard Cost</Value>
                             <Style>
                               <FontWeight>Bold</FontWeight>
                             </Style>
                           </TextRun>
                         </TextRuns>
                         <Style>
                           <TextAlign>Right</TextAlign>
                         </Style>
                       </Paragraph>
                     </Paragraphs>
                     <Style>
                       <Border>
                         <Color>LightGrey</Color>
                         <Style>Solid</Style>
                       </Border>
                       <BackgroundColor>Aqua</BackgroundColor>
                     </Style>
                   </Textbox>
                 </CellContents>
               </TablixHeader>
             </TablixMember>
           </TablixMembers>
         </TablixMember>

The second dynamic column is grouping on the Order Date month. The DataSet contains data for only a single month. Therefore, the example renders only a single column for this dynamic group. The size of the TablixHeader element is equal to the sum of the sizes of the first dynamic column headers. This effectively means that the CellContents span two rendered header rows. The text box is colored pink.

         <TablixMember>
           <Group Name="OrdersGroup">
             <GroupExpressions>
               GroupExpression>=Fields!OrderDate.Value.Month()</GroupExpression>
             </GroupExpressions>
           </Group>
           <SortExpressions>
             <SortExpression>
               <Value>=Fields!OrderDate.Value.Month()</Value>
             </SortExpression>
           </SortExpressions>
           <TablixHeader>
             <Size>0.94271in</Size>
             <CellContents>
               <Textbox Name="OrdersColumnHeader">
                 <CanGrow>true</CanGrow>
                 <KeepTogether>true</KeepTogether>
                 <Paragraphs>
                   <Paragraph>
                     <TextRuns>
                       <TextRun>
                         <Value>Total Orders</Value>
                         <Style>
                           <FontSize>12pt</FontSize>
                           <FontWeight>Bold</FontWeight>
                         </Style>
                       </TextRun>
                     </TextRuns>
                     <Style>
                       <TextAlign>Right</TextAlign>
                     </Style>
                   </Paragraph>
                 </Paragraphs>
                 <Style>
                   <Border>
                     <Color>LightGrey</Color>
                     <Style>Solid</Style>
                   </Border>
                   <BackgroundColor>Pink</BackgroundColor>
                 </Style>
               </Textbox>
             </CellContents>
           </TablixHeader>
         </TablixMember>
       </TablixMembers>
     </TablixColumnHierarchy>

The row hierarchy defines a dynamic group (colored cornsilk in the preceding figure) with a child dynamic group (colored yellow in the figure above) and two static groups which act as header and footer to the child dynamic group.

     <TablixRowHierarchy>

The parent dynamic row is grouping on ProductCategoryName. The text box is colored cornsilk. This dynamic row is repeated for each unique group item, and the child row groups are repeated within it.

       <TablixMembers>
         <TablixMember>
           <Group Name="CategoryGroup">
             <GroupExpressions>
                                 GroupExpression>=Fields!ProductCategoryName.Value</GroupExpression>
             </GroupExpressions>
           </Group>
           <SortExpressions>
             <SortExpression>
               <Value>=Fields!ProductCategoryName.Value</Value>
             </SortExpression>
           </SortExpressions>
           <TablixHeader>

Because the TablixHeader element is within the row hierarchy, the size is the width of a column.

             <Size>1in</Size>
             <CellContents>
               <Textbox Name="CategoryRowHeader">
                 <CanGrow>true</CanGrow>
                 <KeepTogether>true</KeepTogether>
                 <Paragraphs>
                   <Paragraph>
                     <TextRuns>
                       <TextRun>
                         <Value>=Fields!ProductCategoryName.Value</Value>
                       </TextRun>
                     </TextRuns>
                   </Paragraph>
                 </Paragraphs>
                 <Style>
                   <Border>
                     <Color>LightGrey</Color>
                     <Style>Solid</Style>
                   </Border>
                   <BackgroundColor>Cornsilk</BackgroundColor>
                 </Style>
               </Textbox>
             </CellContents>
           </TablixHeader>

The parent dynamic row has a child static member that is used to display row header text at the beginning of each child dynamic row. The header text is "First order received".

           <TablixMembers>
             <TablixMember>
               <TablixHeader>
                 <Size>1.76562in</Size>
                 <CellContents>
                   <Textbox Name="ProductHeaderRowHeader">
                     <CanGrow>true</CanGrow>
                     <KeepTogether>true</KeepTogether>
                     <Paragraphs>
                       <Paragraph>
                         <TextRuns>
                           <TextRun>
                             <Value>First order received</Value>
                             <Style>
                               <FontWeight>Bold</FontWeight>
                             </Style>
                           </TextRun>
                         </TextRuns>
                       </Paragraph>
                     </Paragraphs>
                     <Style>
                       <Border>
                         <Color>LightGrey</Color>
                         <Style>Solid</Style>
                       </Border>
                     </Style>
                   </Textbox>
                 </CellContents>
               </TablixHeader>

Specifying the TablixMember.KeepWithGroup value as "After" means that an attempt is to be made to render this row with the dynamic member (in yellow) that follows.

               <KeepWithGroup>After</KeepWithGroup>
             </TablixMember>

The child dynamic member groups on the ProductName field and will be displayed once for each unique ProductName. The text box is colored yellow.

             <TablixMember>
               <Group Name="Product">
                 <GroupExpressions>
                                         GroupExpression>=Fields!ProductName.Value</GroupExpression>
                 </GroupExpressions>
               </Group>
               <TablixHeader>
                 <Size>1.76562in</Size>
                 <CellContents>
                   <Textbox Name="ProductRowHeader">
                     <CanGrow>true</CanGrow>
                     <KeepTogether>true</KeepTogether>
                     <Paragraphs>
                       <Paragraph>
                         <TextRuns>
                           <TextRun>
                             <Value>=Fields!ProductName.Value</Value>
                           </TextRun>
                         </TextRuns>
                       </Paragraph>
                     </Paragraphs>
                     <Style>
                       <Border>
                         <Color>LightGrey</Color>
                         <Style>Solid</Style>
                       </Border>
                       <BackgroundColor>Yellow</BackgroundColor>
                     </Style>
                   </Textbox>
                 </CellContents>
               </TablixHeader>
             </TablixMember>

The parent dynamic row has a child static member that is used to display row footer text at the end of each child dynamic row. The footer text is "Total".

             <TablixMember>
               <TablixHeader>
                 <Size>1.76562in</Size>
                 <CellContents>
                   <Textbox Name="ProductFooterRowHeader">
                     <CanGrow>true</CanGrow>
                     <KeepTogether>true</KeepTogether>
                     <Paragraphs>
                       <Paragraph>
                         <TextRuns>
                           <TextRun>
                             <Value>Total</Value>
                             <Style>
                               <FontWeight>Bold</FontWeight>
                             </Style>
                           </TextRun>
                         </TextRuns>
                       </Paragraph>
                     </Paragraphs>
                     <Style>
                       <Border>
                         <Color>LightGrey</Color>
                         <Style>Solid</Style>
                       </Border>
                       <TopBorder>
                         <Color>Black</Color>
                       </TopBorder>
                       <BottomBorder>
                         <Color>Black</Color>
                         <Width>2pt</Width>
                       </BottomBorder>
                     </Style>
                   </Textbox>
                 </CellContents>
               </TablixHeader>

Specifying the TablixMember.KeepWithGroup value as "Before" means that an attempt is to be made to render this row with the preceding dynamic member (in yellow).

               <KeepWithGroup>Before</KeepWithGroup>
             </TablixMember>
           </TablixMembers>
         </TablixMember>
       </TablixMembers>
     </TablixRowHierarchy>

A TablixCorner element is specified (colored lime in the preceding figure) to occupy the top left corner. Observe that there is no ability to specify width or heights within the TablixCorner. The width of the columns is defined by the size of the TablixHeader elements in the row hierarchy. The height of the rows is defined by the size of the TablixHeader elements in the column hierarchy.

     <TablixCorner>
       <TablixCornerRows>

There are two TablixCornerRow elements specified. Two are required because of the following rule that is stated in sections 2.23 and 2.37.1:

"If a TablixCorner element is specified, the quantity of descendant TablixCornerRow elements in the tablix MUST equal the quantity of unique cumulative heights for each tablix column member of the tablix. 'Cumulative height' for a tablix column member is defined as the sum of the values of all TablixHeader.Size elements that are descendants of the tablix column member."

Column hierarchy

Size

Cumulative height

Tablix member (SalesPerson)

.43438

.43438

Tablix member "List Price"

.43438

.43438 +.45833 = .94721

Tablix member "Standard Cost"

.43438

.43438 +.45833 = .94721

Tablix member (SalesPerson)

.94721

.94721

Computation of quantity of TablixCornerRow elements

This table shows the structure of the TablixHeaders within the column hierarchy, identifying the size values. The cumulative height calculation shows the addition of the RdlSize with all of its parent's RdlSizes. There are two unique cumulative heights: these are .48438 and .94721. Therefore, there need to be two TablixCornerRow elements.

There are two TablixCornerCell elements specified in each row. Two are required because of the following rule that is stated in sections 2.23 and 2.38.1:

"If a TablixCornerRow element is specified, the quantity of descendant TablixCornerCell elements in the tablix MUST equal the quantity of unique cumulative widths for each tablix row member of the tablix. 'Cumulative width' for a tablix row member is defined as the sum of the values of all TablixHeader.Size elements that are descendants of the tablix row member."

Row hierarchy

Size

Cumulative width

Tablix member (ProductCategoryName)

1.00000

1.00000

Tablix member "First order received"

1.76562

1.00000 + 1.76562= 2.76562

Tablix member (ProductName)

1.76562

1.00000 + 1.76562= 2.76562

Tablix member "Total"

1.76562

1.00000 + 1.76562= 2.76562

Tablix example 3—computation of quantity of TablixCornerCell elements

The preceding table shows the structure of the TablixHeaders within the row hierarchy, identifying the size values. The cumulative width calculation shows the addition of the size with all of its parent's sizes. There are two unique cumulative heights: these are 1.00000 and 1.76562. Therefore, there need to be two TablixCornerCell elements in each TablixCornerRow element.

         <TablixCornerRow>
           <TablixCornerCell>
             <CellContents>
               <Textbox Name="Textbox4">
                 <CanGrow>true</CanGrow>
                 <KeepTogether>true</KeepTogether>
                 <Paragraphs>
                   <Paragraph>
                     <TextRuns>
                       <TextRun>
                         <Value>Bicycle sales for June 2004</Value>
                         <Style>
                           <FontSize>12pt</FontSize>
                           <FontWeight>Bold</FontWeight>
                           <TextDecoration>Underline</TextDecoration>
                         </Style>
                       </TextRun>
                     </TextRuns>
                   </Paragraph>
                 </Paragraphs>
                 <Style>
                   <Border>
                     <Color>LightGrey</Color>
                     <Style>Solid</Style>
                   </Border>
                   <BackgroundColor>Lime</BackgroundColor>
                 </Style>
               </Textbox>

The first row of the corner has a title that uses two cells. The CellContents specifies a ColSpan of 2 for the first TablixCornerCell and the second TablixCornerCell is specified as empty.

               <ColSpan>2</ColSpan>
             </CellContents>
           </TablixCornerCell>
           <TablixCornerCell />
         </TablixCornerRow>

The second row of the corner contains two text boxes to display "Category" and "Product Name" as column titles over the row headers.

         <TablixCornerRow>
           <TablixCornerCell>
             <CellContents>
               <Textbox Name="Textbox18">
                 <CanGrow>true</CanGrow>
                 <KeepTogether>true</KeepTogether>
                 <Paragraphs>
                   <Paragraph>
                     <TextRuns>
                       <TextRun>
                         <Value>Category</Value>
                         <Style>
                           <FontWeight>Bold</FontWeight>
                         </Style>
                       </TextRun>
                     </TextRuns>
                   </Paragraph>
                 </Paragraphs>
                 <Style>
                   <Border>
                     <Color>LightGrey</Color>
                     <Style>Solid</Style>
                   </Border>
                   <BackgroundColor>Lime</BackgroundColor>
                 </Style>
               </Textbox>
             </CellContents>
           </TablixCornerCell>
           <TablixCornerCell>
             <CellContents>
               <Textbox Name="Textbox7">
                 <CanGrow>true</CanGrow>
                 <KeepTogether>true</KeepTogether>
                 <Paragraphs>
                   <Paragraph>
                     <TextRuns>
                       <TextRun>
                         <Value>Product Name</Value>
                         <Style>
                           <FontWeight>Bold</FontWeight>
                         </Style>
                       </TextRun>
                     </TextRuns>
                   </Paragraph>
                 </Paragraphs>
                 <Style>
                   <Border>
                     <Color>LightGrey</Color>
                     <Style>Solid</Style>
                   </Border>
                   <BackgroundColor>Lime</BackgroundColor>
                 </Style>
               </Textbox>
             </CellContents>
           </TablixCornerCell>
         </TablixCornerRow>
       </TablixCornerRows>
     </TablixCorner>

The body of the tablix defines the cells that can repeat for both columns and rows. The widths of each TablixColumn specify the width of each column as it repeats.

     <TablixBody>
       <TablixColumns>
         <TablixColumn>
           <Width>1.47396in</Width>
         </TablixColumn>
         <TablixColumn>
           <Width>1.29167in</Width>
         </TablixColumn>
         <TablixColumn>
           <Width>1in</Width>
         </TablixColumn>
       </TablixColumns>
       <TablixRows>
         <TablixRow>

The heights of each TablixRow specify the height of each row as it repeats.

           <Height>0.25in</Height>
           <TablixCells>
             <TablixCell>
               <CellContents>
                 <Textbox Name="OrderDate">
                   <CanGrow>true</CanGrow>
                   <KeepTogether>true</KeepTogether>
                   <Paragraphs>
                     <Paragraph>
                       <TextRuns>
                         <TextRun>

Because the cells are being used within groups, the data expression uses aggregate functions.

                           <Value>=First(Fields!OrderDate.Value)</Value>
                           <Style>
                             <Format>MMM dd, yyyy</Format>
                           </Style>
                         </TextRun>
                       </TextRuns>
                       <Style>
                         <TextAlign>Center</TextAlign>
                       </Style>
                     </Paragraph>
                   </Paragraphs>
                   <Style>
                     <Border>
                       <Color>LightGrey</Color>
                       <Style>Solid</Style>
                     </Border>
                   </Style>
                 </Textbox>

The CellContents for the TablixCell spreads across two columns using a ColSpan element. This means that the following TablixCell needs to be specified as empty.

                 <ColSpan>2</ColSpan>
               </CellContents>
             </TablixCell>
             <TablixCell />
             <TablixCell>
               <CellContents>
                 <Textbox Name="Textbox40">
                   <CanGrow>true</CanGrow>
                   <KeepTogether>true</KeepTogether>
                   <Paragraphs>
                     <Paragraph>
                       <TextRuns>
                         <TextRun>
                           <Value />
                         </TextRun>
                       </TextRuns>
                       <Style>
                         <TextAlign>Center</TextAlign>
                       </Style>
                     </Paragraph>
                   </Paragraphs>
                   <Style>
                     <Border>
                       <Color>LightGrey</Color>
                       <Style>Solid</Style>
                     </Border>
                     <BackgroundColor>Pink</BackgroundColor>
                   </Style>
                 </Textbox>
               </CellContents>
             </TablixCell>
           </TablixCells>
         </TablixRow>
         <TablixRow>
           <Height>0.39062in</Height>
           <TablixCells>
             <TablixCell>
               <CellContents>
                 <Textbox Name="ListPrice">
                   <CanGrow>true</CanGrow>
                   <KeepTogether>true</KeepTogether>
                   <Paragraphs>
                     <Paragraph>
                       <TextRuns>
                         <TextRun>

The cell is associated with the Product dynamic group. The aggregate function will apply across the same scope.

                           <Value>=Sum(Fields!ListPrice.Value)</Value>
                         </TextRun>
                       </TextRuns>
                     </Paragraph>
                   </Paragraphs>
                   <Style>
                     <Border>
                       <Color>LightGrey</Color>
                       <Style>Solid</Style>
                     </Border>
                   </Style>
                 </Textbox>
               </CellContents>
             </TablixCell>
             <TablixCell>
               <CellContents>
                 <Textbox Name="StandardCost">
                   <CanGrow>true</CanGrow>
                   <KeepTogether>true</KeepTogether>
                   <Paragraphs>
                     <Paragraph>
                       <TextRuns>
                         <TextRun>
                           <Value>=Sum(Fields!StandardCost.Value)</Value>
                         </TextRun>
                       </TextRuns>
                     </Paragraph>
                   </Paragraphs>
                   <Style>
                     <Border>
                       <Color>LightGrey</Color>
                       <Style>Solid</Style>
                     </Border>
                   </Style>
                 </Textbox>
               </CellContents>
             </TablixCell>
             <TablixCell>
               <CellContents>
                 <Textbox Name="OrderQty">
                   <CanGrow>true</CanGrow>
                   <KeepTogether>true</KeepTogether>
                   <Paragraphs>
                     <Paragraph>
                       <TextRuns>
                         <TextRun>
                           <Value>=Sum(Fields!OrderQty.Value)</Value>
                         </TextRun>
                       </TextRuns>
                     </Paragraph>
                   </Paragraphs>
                   <Style>
                     <Border>
                       <Color>LightGrey</Color>
                       <Style>Solid</Style>
                     </Border>
                     <BackgroundColor>Pink</BackgroundColor>
                   </Style>
                 </Textbox>
               </CellContents>
             </TablixCell>
           </TablixCells>
         </TablixRow>
         <TablixRow>
           <Height>0.25in</Height>
           <TablixCells>
             <TablixCell>
               <CellContents>
                 <Textbox Name="ListPrice1">
                   <CanGrow>true</CanGrow>
                   <KeepTogether>true</KeepTogether>
                   <Paragraphs>
                     <Paragraph>
                       <TextRuns>
                         <TextRun>

This cell is associated with the static group under the dynamic grouping of Product Category. The aggregate will apply to Product Category.

                           <Value>=Sum(Fields!ListPrice.Value)</Value>
                         </TextRun>
                       </TextRuns>
                     </Paragraph>
                   </Paragraphs>
                   <Style>
                     <Border>
                       <Color>LightGrey</Color>
                       <Style>Solid</Style>
                     </Border>
                     <TopBorder>
                       <Color>Black</Color>
                     </TopBorder>
                     <BottomBorder>
                       <Color>Black</Color>
                       <Width>2pt</Width>
                     </BottomBorder>
                   </Style>
                 </Textbox>
               </CellContents>
             </TablixCell>
             <TablixCell>
               <CellContents>
                 <Textbox Name="StandardCost1">
                   <CanGrow>true</CanGrow>
                   <KeepTogether>true</KeepTogether>
                   <Paragraphs>
                     <Paragraph>
                       <TextRuns>
                         <TextRun>
                           <Value>=Sum(Fields!StandardCost.Value)</Value>
                         </TextRun>
                       </TextRuns>
                     </Paragraph>
                   </Paragraphs>
                   <Style>
                     <Border>
                       <Color>LightGrey</Color>
                       <Style>Solid</Style>
                     </Border>
                     <TopBorder>
                       <Color>Black</Color>
                     </TopBorder>
                     <BottomBorder>
                       <Color>Black</Color>
                       <Width>2pt</Width>
                     </BottomBorder>
                   </Style>
                 </Textbox>
               </CellContents>
             </TablixCell>
             <TablixCell>
               <CellContents>
                 <Textbox Name="Textbox42">
                   <CanGrow>true</CanGrow>
                   <KeepTogether>true</KeepTogether>
                   <Paragraphs>
                     <Paragraph>
                       <TextRuns>
                         <TextRun>
                           <Value>=Sum(Fields!OrderQty.Value)</Value>
                         </TextRun>
                       </TextRuns>
                     </Paragraph>
                   </Paragraphs>
                   <Style>
                     <Border>
                       <Color>LightGrey</Color>
                       <Style>Solid</Style>
                     </Border>
                     <TopBorder>
                       <Color>Black</Color>
                     </TopBorder>
                     <BottomBorder>
                       <Color>Black</Color>
                       <Width>2pt</Width>
                     </BottomBorder>
                     <BackgroundColor>Pink</BackgroundColor>
                   </Style>
                 </Textbox>
               </CellContents>
             </TablixCell>
           </TablixCells>
         </TablixRow>
       </TablixRows>
     </TablixBody>
     <DataSetName>DataSet1</DataSetName>
     <Style>
       <Border>
         <Style>None</Style>
       </Border>
     </Style>
   </Tablix>