3.8 Tablix 2

The following is an example RDL definition of a Tablix element that is used to lay out data in a straightforward manner. The tablix uses text boxes within cells to format and display the data. This layout provides similar functionality to the Table element in versions of RDL prior to 2008/01. The data is fetched from the Microsoft Adventure Works example database. The top of the rendered definition is shown in the following figure.

Tablix example 2

Figure 18: Tablix example 2

The Tablix element has its Tablix.Name attribute set to "Tablix2". It is positioned 1 inch from the left edge of its container.

   <Tablix Name="Tablix2">
     <Left>1in</Left>

The entire tablix is rendered only if the value of the ShowTable parameter is set to false. If it is rendered, a page break is wanted before the tablix appears, and after the last row of the rendered tablix, another page break is wanted.

     <Visibility>
       <Hidden>=Parameters!ShowTable.Value=False</Hidden>
     </Visibility>
     <PageBreak>
       <BreakLocation>StartAndEnd</BreakLocation>
     </PageBreak>

There are three static columns in this tablix, so three TablixCell elements are required in each row (or fewer if one of the cells spans more than one column).

     <TablixColumnHierarchy>
       <TablixMembers>
         <TablixMember />
         <TablixMember />
         <TablixMember />
       </TablixMembers>
     </TablixColumnHierarchy>

The TablixRowHierarchy element specifies two rows. The first is a static row that is to be kept with the dynamic row that follows. This row is to behave as a column header. Therefore, the row has a TablixMember.KeepWithGroup element that has a value of After and a TablixMember.RepeatOnNewPage element that has a value of true.

     <TablixRowHierarchy>
       <TablixMembers>
         <TablixMember>
           <KeepWithGroup>After</KeepWithGroup>
           <RepeatOnNewPage>true</RepeatOnNewPage>
         </TablixMember>

The second row is a detail group with a SortExpression that causes the data in the group to appear in order of city name, A–Z.

         <TablixMember>
           <Group Name="Details" />
           <SortExpressions>
             <SortExpression>
               <Value>=Fields!City.Value</Value>
             </SortExpression>
           </SortExpressions>
         </TablixMember>
       </TablixMembers>
     </TablixRowHierarchy>

The three columns defined by the TablixColumnHierarchy are set up with specific widths.

     <TablixBody>
       <TablixColumns>
         <TablixColumn>
           <Width>2in</Width>
         </TablixColumn>
         <TablixColumn>
           <Width>1.5in</Width>
         </TablixColumn>
         <TablixColumn>
           <Width>3cm</Width>
         </TablixColumn>
       </TablixColumns>

The first row is set to 0.3 inches high and contains three cells. Each cell has an aqua background and has a light gray border, created by setting the properties on the descendant text boxes. The text in each text box is set as a header to the columns, Address, City, and Country.

  
       <TablixRows>
         <TablixRow>
           <Height>0.3in</Height>
           <TablixCells>
             <TablixCell>
               <CellContents>
                 <Textbox Name="Heading1">
                   <KeepTogether>true</KeepTogether>
                   <Paragraphs>
                     <Paragraph>
                       <TextRuns>
                         <TextRun>
                           <Value>Address</Value>
                         </TextRun>
                       </TextRuns>
                     </Paragraph>
                   </Paragraphs>
                   <Style>
                     <Border>
                       <Color>LightGrey</Color>
                       <Style>Solid</Style>
                     </Border>
                     <BackgroundColor>Aqua</BackgroundColor>
                   </Style>
                 </Textbox>
               </CellContents>
             </TablixCell>
             <TablixCell>
               <CellContents>
                 <Textbox Name="Heading2">
                   <Paragraphs>
                     <Paragraph>
                       <TextRuns>
                         <TextRun>
                           <Value>City</Value>
                         </TextRun>
                       </TextRuns>
                     </Paragraph>
                   </Paragraphs>
                   <Style>
                     <Border>
                       <Color>LightGrey</Color>
                       <Style>Solid</Style>
                     </Border>
                     <BackgroundColor>Aqua</BackgroundColor>
                   </Style>
                 </Textbox>
               </CellContents>
             </TablixCell>
             <TablixCell>
               <CellContents>
                 <Textbox Name="Heading3">
                   <KeepTogether>true</KeepTogether>
                   <Paragraphs>
                     <Paragraph>
                       <TextRuns>
                         <TextRun>
                           <Value>Country</Value>
                         </TextRun>
                       </TextRuns>
                     </Paragraph>
                   </Paragraphs>
                   <Style>
                     <Border>
                       <Color>LightGrey</Color>
                       <Style>Solid</Style>
                     </Border>
                     <BackgroundColor>Aqua</BackgroundColor>
                   </Style>
                 </Textbox>
               </CellContents>
             </TablixCell>
           </TablixCells>
         </TablixRow>

The second row is associated with the row hierarchy that is a detail group; it will therefore be repeated for each row of data. The row is set to 0.6 inches high, but this will increase if the data needs more space because the descendant Textbox elements have the Textbox.CanGrow element specified with a value of true. As with the headings, each cell will appear to have a solid, light gray border because each descendant text box has that border defined.

         <TablixRow>
           <Height>0.6in</Height>
           <TablixCells>
             <TablixCell>
               <CellContents>
                 <Textbox Name="Address">
                   <CanGrow>true</CanGrow>
                   <KeepTogether>true</KeepTogether>
                   <Paragraphs>
                     <Paragraph>
                       <TextRuns>
                         <TextRun>
                           <Value>=Fields!AddressLine1.Value</Value>
                         </TextRun>
                       </TextRuns>
                     </Paragraph>
                     <Paragraph>
                       <TextRuns>
                         <TextRun>
                           <Value>=Fields!AddressLine2.Value</Value>
                         </TextRun>
                       </TextRuns>
                     </Paragraph>
                   </Paragraphs>
                   <Style>
                     <Border>
                       <Color>LightGrey</Color>
                       <Style>Solid</Style>
                     </Border>
                     <PaddingLeft>2pt</PaddingLeft>
                   </Style>
                 </Textbox>
               </CellContents>
             </TablixCell>
             <TablixCell>
               <CellContents>
                 <Textbox Name="Area">
                   <CanGrow>true</CanGrow>
                   <KeepTogether>true</KeepTogether>
                   <Paragraphs>
                     <Paragraph>
                       <TextRuns>
                         <TextRun>
                           <Value>=Fields!City.Value</Value>
                           <Style>
                             <FontWeight>Bold</FontWeight>
                           </Style>
                         </TextRun>
                       </TextRuns>
                     </Paragraph>
                     <Paragraph>
                       <TextRuns>
                         <TextRun>
                           <Value>=Fields!StateProvince.Value</Value>
                         </TextRun>
                       </TextRuns>
                     </Paragraph>
                     <Paragraph>
                       <TextRuns>
                         <TextRun>
                           <Value>=Fields!PostalCode.Value</Value>
                         </TextRun>
                       </TextRuns>
                     </Paragraph>
                   </Paragraphs>
                   <Style>
                     <Border>
                       <Color>LightGrey</Color>
                       <Style>Solid</Style>
                     </Border>
                     <PaddingLeft>2pt</PaddingLeft>
                   </Style>
                 </Textbox>
               </CellContents>
             </TablixCell>
             <TablixCell>
               <CellContents>
                 <Textbox Name="Country">
                   <CanGrow>true</CanGrow>
                   <KeepTogether>true</KeepTogether>
                   <Paragraphs>
                     <Paragraph>
                       <TextRuns>
                         <TextRun>
                           <Value>=Fields!CountryRegion.Value</Value>
                         </TextRun>
                       </TextRuns>
                     </Paragraph>
                   </Paragraphs>
                   <Style>
                     <Border>
                       <Color>LightGrey</Color>
                       <Style>Solid</Style>
                     </Border>
                     <PaddingLeft>2pt</PaddingLeft>
                   </Style>
                 </Textbox>
               </CellContents>
             </TablixCell>
           </TablixCells>
         </TablixRow>
       </TablixRows>
     </TablixBody>
  

If possible, the entire tablix is to be rendered on a single page.

     <KeepTogether>true</KeepTogether>
  

The entire tablix has a tooltip of "Addresses" and a solid border of the default color around it.

     <ToolTip>Addresses</ToolTip>
     <Style>
       <Border>
         <Style>Solid</Style>
       </Border>
     </Style>
     <DataSetName>AddressDataSet</DataSetName>
   </Tablix>