This article describes how to go from a standard table...
...to a table with spans or sub-headings:
Requirements
- A table. In this example, we are adding row spans, so the labels you want to create spans for must exist in the rows.
- You have read How to Create a Custom Rule.
Method
1. Select your table.
2. Go to Data > Rules on the object inspector.
3. Click the Plus (+) button.
4. Click New custom rule (write your own JavaScript) > Edit JavaScript.
5. Paste the below into the dialog:
form.setHeading("Add row spans");
form.setSummary("Add row spans");
// Span the Coke brands.
table.spanRows([table.rowIndex('Coca-Cola'),
table.rowIndex('Diet Coke'),
table.rowIndex('Coke Zero')],
'Coke Brands');
// Span the Pepsi brands.
table.spanRows([table.rowIndex('Diet Pepsi'),
table.rowIndex('Pepsi Max'),
table.rowIndex('Pepsi')],
'Pepsi Brands');
- In this code, we use
table.spanRows
to define the rows to be covered by the span. The format for the arguments istable.spanRows([index1,index2,...], label)
, whereby we usetable.rowIndex
to return the index of the specified label. - Note, unlike when creating a span via a table's context menu, this change is only made to tables with this Rule applied.
6. OPTIONAL: If you have a crosstab and then switch rows and columns, you will need to apply this rule to the columns instead. In this case, you should update the function references to spanColumns
and columnIndex
respectively.
7. Press the Play button > OK > OK.
Next
How to Add a Custom Table Footnote