Tables

In the example Employee Listing report from Chapter 3, The BIRT Environment and First Report, we used a visual report element called a Table, even if we didn't know it. The Table is similar to the Grid component we saw in the previous chapter, except that it is data bound. What this means is that the contents of this component are populated by data stored in a data container such as a dataset. In the Employee Listing report, we saw a shortcut method for creating a table. This is very useful when we are building simple listing reports. However, when we need more precise control over our Table, we can also do it manually using the Palette component.

The Table is divided into three logical groups:

  • Header, which will contain the name of each report column in the report
  • Details, which will actually contain the data returned from the bound dataset
  • Footer, which will contain summary or aggregate information about a report

In the following example, we are going to demonstrate two different ways to create tables. First we will build tables using the shortcut drag-and-drop dataset method. Then we will use the second method, which involves manually building a table, binding it to a dataset, and populating the elements of the table.

Creating tables using drag and drop

First we want to get the data from dsetJoined and move it over to our Layout view. There are a couple of different ways this can be accomplished. We can drag it over from the Data Explorer just like we did in Chapter 3 or we can drag it over from the Outline view. If we right-click on the dsetOrders, we can also choose the Insert into Layout option. The caveat with this is that if there is already any element in the layout, we will have to click on an empty space in the Layout editor for this option to be available.

  1. In the Data Explorer, under Data Sets, right-click on dsetJoined and choose Insert in Layout.
    Creating tables using drag and drop
  2. From the Outline, under the Body branch, select Table.
    Creating tables using drag and drop
  3. Under the Property Editor, change the Name to tblEmployeePayments.
    Creating tables using drag and drop
  4. In the Layout Editor, find the cells that say dsetFlatFilePayments: firstName and dsetFlatFilePayments. Click on the grey square above these labels to select that entire column. Then right-click, and choose Delete. Repeat this for both columns.
    Creating tables using drag and drop
  5. We need to change each of the column headers contents so that they do not contain dsetXMLEmployee:: or dsetFlatFilePayments. To do this, we can either double-click on each of them or can use the Property Editor. To use the Property Editor, select the label element either in the Layout Editor or, using the Outline, select the label under each of the Body, Table, Header, Row, Cell, Label components. Then in the Property Editor, scroll down to Advanced and select Content. Change each label to an appropriate title.
    Creating tables using drag and drop
  6. From the Outline view, select Body | Table | Header | Row. In the Property Editor, choose the Font category and change it to Bold.
    Creating tables using drag and drop
  7. In the Layout Editor, click on the Detail cell under the Payment Amount column. Under Using the Property Editor, under the Format Number category, set the Format as property to Currency. Check the Use 1000s separator checkbox and select the $ as Symbol.
    Creating tables using drag and drop
  8. We now want to add an aggregation for the Payment Amount column. We can drag the Aggregate component over from the Component palette. Drag the component over to the footer row, in the Payment Amount column.
  9. Enter the following information:
    • Column Binding Name: agrPaymentTotal
    • Display Name: Total Payments
    • Data Type: Float
    • Function: SUM
    • Data Field: select PaymentAmount from the drop-down list.
    Creating tables using drag and drop
  10. Click on the agrPaymentTotal component and format it as Currency.
    Creating tables using drag and drop
  11. Click on Preview under the Layout Editor.
Creating tables using drag and drop

So, creating a simple report this way is easy enough, but how would we do so manually. Well, that's exactly what we are going to do next.

Creating tables manually

We want to create a table right below this one with the information from the dsetOrders. We will create this one manually as we do not want to display all the information in that dataset, but only certain columns. Because we should be fairly familiar with using the Component palette at this point, we are going to create this table directly in the Layout Editor.

  1. Right-click in the area below the tblEmployeePayments, and choose Insert | Table.
    Creating tables manually
  2. For dimensions, use 6 columns, 1 detail row, and use dsOrders as the dataset.
  3. In the first column of the Detail row, right-click, and choose Insert | Data.
    Creating tables manually
  4. Enter the following information:
    • Column Binding Name: cbOrderNumber
    • Display Name: Order Number
    • Data Type: Integer
    • Expression: row["ORDERNUMBER"]

      Here, we manually created a data element in the detail row. Note the expression. This expression is telling BIRT to use the value or ORDERNUMBER in the current row, as the detail band in a table will cycle through every record returned in a dataset.

  5. Click OK.
    Creating tables manually
  6. Right-click in the first column of the Header row, and select Insert | Label. For the value, type in Order Number.
  7. Now that we have seen how to do that manually, here is an easier way. Open up the Data Explorer and expand on the dsetOrders node. Drag over the CUSTOMERNUMBER field to the detail rows second column. We can see the header label is automatically created.
  8. Repeat for the PRODUCTCODE, PRICEEACH, and QUANTITYORDERED field.
  9. Click on the grey square at the top off the last column to select the entire last column. Once done, right-click and select Insert | Column to the right.
    Creating tables manually
  10. Right-click on the new detail cell, and insert a new data element. Use the following information:
    • Display Name: Product Total
    • Data Type: Float
    • Expression: row["PRICEEACH"] * row["QUANTITYORDERED"]
  11. Create a label for this column titled Product Total.
  12. Format both the Product Total detail cell and the PRICEEACH cell as Currency.
  13. Save and preview the table.
Creating tables manually
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset