Tables and grids enable you to view and present item data in a way that makes comparing and contrasting the information easy. When preparing to create a table or grid, the first questions to consider are:

  • "What will constitute a row in my table/grid?" 
  • "What information do I want to pull in on each row?
  • "Are there scenarios where some data may not exist?"

The scripting of tables and grids within SystemWeaver is very similar. They both typically have a static number of defined columns and a number of rows that depend on the current item structure, its parts, etc. However, the two have slightly different uses. This article compares the two, and introduces the basics of table and grid configuration. 


Prerequisites


Comparing Tables and Grids

When it comes to configuration, tables and grids share most of the same elements. Therefore, a table can easily be converted to a grid and vice versa. Which one you chose to use will depend on what your needs are as they have slightly different purposes:


TableGrid
Tables exist for the purpose of formatting data in reports and documents for review and/or printing.
  • Included in report configuration
  • Can be inter-dispersed with text in a report to enhance readability
  • Not editable
  • Must fit into the width of a printed page
Grids exist to give you an overview of the data and enable you to sort and filter that information. It's also possible to export grid data to Excel.
  • Excel-like matrixes that can be generated from data in SystemWeaver
  • Provides a good overview of information
  • Ability to filter, sort and group data as needed
  • Can be exported to Excel or CSV
  • Can be scrolled in a window
  • Some elements can be made editable


Example Configuration of Table and Grid 

Below is an example of the "same" table and grid configuration using the "Vehicle Specification" data below. The result is very similar.


Table in a Report

<Report>
  <Table>
    <Columns>
      <ItemNameColumn objectName="comp" caption="Component" width="100"/>
      <ItemNameColumn caption="Requirement" width="75"/>
      <ItemAttributeColumn caption="Priority" type="PRIO" width="75"/>
      <ItemAttributeColumn caption="Verification Method" type="ABVM" width="75"/> 
    </Columns>
    <ForEachPart type="XESX">
      <DefObj>
        <ForEachPart type="EXAC">
          <DefObj>
            <RowObject name="comp">
              <ForEachPart type="IBAR">
                <DefObj>
                  <Row/>
                </DefObj>
              </ForEachPart>
            </RowObject>
          </DefObj>
        </ForEachPart>
      </DefObj>
    </ForEachPart>
  </Table>
</Report>


Grid

<Grid>
    <Columns>
        <ItemNameColumn objectName="comp" caption="Component" width="120"/>
        <ItemNameColumn caption="Requirement" width="75"/>
        <ItemAttributeColumn caption="Priority" type="PRIO" width="75"/>
        <ItemAttributeColumn caption="Verification Method" type="ABVM" width="120"/> 
    </Columns>
    <ForEachPart type="XESX">
        <DefObj>
            <ForEachPart type="EXAC">
                <DefObj>
                    <RowObject name="comp">
                        <ForEachPart type="IBAR">
                            <DefObj>
                                <Row/>
                            </DefObj>
                        </ForEachPart>
                    </RowObject>
                </DefObj>
            </ForEachPart>
        </DefObj>
    </ForEachPart>
</Grid>


Configuring the View

A configurable grid, and a report that contains a table, are both Config items, and are created using the config item Sandbox mode as described in Creating Config Item Views. By default, the Sandbox for Grids will include the basic elements of a configuration to get you started, as shown below. 



Tip: When using the Sandbox Mode, the content of the sandbox can be lost when you switch to another item and change view. We recommend that you save intermediate revisions not ready to be published in NotePad or some external editor.


Explanation of the Configuration Elements

Below is a list of the basic elements using a table configuration as an example, however, these can easily be translated for use with grids as well. A complete list of configuration elements can be found in the SystemWeaver Script Language Reference Manual in the Help.


As with all configurable features, table/grid definitions consist of a definition part and a data collection part:

  • The columns defining the layout and what type of data that is to be shown in them
  • The data collection where the rows are populated


Definition

<Grid> is the starting point of a grid definition. It has an optional optimized attribute which defines whether or not each cell value in item columns will be recalculated as needed or not. Valid values are "true" or "false". A null value is equivalent to "false".

  • "true": Each value will only be calculated once when you are working in the grid. This is suitable if the grid is for obtaining a "snapshot" that will be exported to Excel, etc. Grid generation and export times are optimized. 
  • "false": Each value is recalculated as needed when you are working/editing in the grid. This is suitable if you always want the values to be updated. Grid generation and export times will include obtaining all relevant up-to-date values from the database.


<Table> is used for a table in a report configuration. It has an optional autoMerge attribute to define if adjacent cells in a column with the same object should be merged. A "True" value will merge the cells. 


Tables can have a header row as well as styles, a table caption, and a specified cell border width. To find out more about these options, see Formatting Tables in Reports and Documents.


<Columns> contains the columns. There are a number of different column options you can include here. A complete list of them can be found in the application Help in the Basic SystemWeaver Script Language section under Grid or Table sections. In grids, some columns can be configured to allow users to edit values directly in the grid, using the readOnly attribute.


Example showing three types of columns:  

...
  <Columns>
           <ItemNameColumn caption="Requirement" width="200"/> (A)
           <AttributeColumn caption="Prio" type="PRIO" readOnly="false"/> (B)
           <ItemAttributeColumn caption="Verification Method" width="150" type="ABVM"/>  (C)
  </Columns> 
 ...  



Note: For grids and tables, if you want to include Description content, the only way is to use <DescriptionColumn/>. The reason for this is that this column type is the only one that has an underlying component that can display the Description data. Currently, there is no means of accessing the description of an item using the Path Query Language.


Data Collection

<Row> is used to populate the table with data. It has to be included in the <Table>, otherwise no rows will be printed. The below report will include the data for the item currently selected in the structure tree, in this case Requirement.


<Report>
   <Table>

      <Columns>
            <ItemNameColumn caption="Requirement" width="200"/> 
            <AttributeColumn caption="Prio" type="PRIO"/>
            <ItemAttributeColumn caption="Verification Method" width="150" type="ABVM"/> 
      </Columns>

      <Row/> 

   </Table>
</Report>


<ForEachPart> and <DefObj> can be used in the table/grid to view data for multiple parts. You can use the <ForEachPart> tag along with <DefObj> for each part and place them just above the <Row/> line.  The below example will provide two types of data (Name value and one attribute value) for one part (Requirements with part SID=IBAR).


Example:

<Report>
    <Table>

        <Columns>  
            <ItemNameColumn caption="Requirement" width="200"/> 
            <ItemAttributeColumn caption="Verification Method" width="150" type="ABVM"/>
        </Columns>

        <ForEachPart type="XESX">
            <DefObj>
                <ForEachPart type="EXAC">
                    <DefObj>                       
                        <ForEachPart type="IBAR">
                            <DefObj>                                            

                                <Row/>  

                            </DefObj>
                        </ForEachPart>                          
                    </DefObj>
                </ForEachPart>                  
            </DefObj>
        </ForEachPart>

    </Table>
</Report>


Tip: Remember, you can find the SID values for a part by either adding the Part SID column to your structure tree (Using the Structure Tree Grid) or by selecting the part, loading the Parts view and adding the SID column to the view. See Finding SystemWeaver Type Identifiers (SIDs) for more information.


For additional explanation on how rows should be created, see Tables/Grids and Rows.


<RowObject> can be used when you want to combine multiple items' data on one line. For example, you might want to list Application Components and their Requirements both of which are items. RowObject connects the current item with a column identified by an objectName attribute in the column definition. The name attribute should be unique. The objectName value in a column and the RowObject name value must be identical.


Example:

<RowObject name=”comp”> is used to indicate that the item or part is stored in a ”variable” called ”comp” for later use. When defining a column, you then indicate that the object stored in variable ”comp” be used in the column by setting the attribute objectName to ”comp”.

<Report>
	<Table> 
	
		<Columns>
			<ItemNameColumn objectName="comp" caption="Component" width="120"/>
			<ItemNameColumn caption="Requirement" width="75"/> 
			<ItemAttributeColumn caption="Priority" type="PRIO" width="75"/>
		</Columns>
		
		<RowObject name="comp">
			<ForEachPart type="IBAR">
				<DefObj>
					<Row/>
				</DefObj>
			</ForEachPart>
		</RowObject>
		
	</Table>
</Report>


<Row> </Row> can be used instead of <Row/> if you want to have multiple values in one cell. This is achieved by letting <Row> </Row> encapsulate a part, and using RowObject to store the objects to put into a column. In the below example, <RowObject name="req"/> is used to capture the Name of each Requirement of type "IBAR".

<Report> 
    <Table>

        <Columns> 
            <ItemNameColumn objectName="comp" caption="Component" width="150"/>
            <ItemNameColumn objectName="req" caption="Requirements" width="150"/>
        </Columns>

        <RowObject name="comp">
            <Row>
                <ForEachPart type="IBAR">
                    <DefObj>
                        <RowObject name="req"/>
                    </DefObj>
                </ForEachPart>
            </Row>
        </RowObject>

    </Table>
</Report>


Tip: You can use <RowObject name=””/> multiple times inside <Row> </Row>.


What's Next?

Interested in SystemWeaver Script Language training? Learn about the numerous scripting options in the SystemWeaver Script Language Reference Manual in the Help.