---
title: "Column Selection - Dynamic"
canonical: "https://support.appfire.com/space/TBL/74814521/Column%20Selection%20-%20Dynamic"
format: markdown
---
# Requirements

- [Run Self-Service Reports for Confluence](https://appfire.atlassian.net/wiki/spaces/RUN) for the [Run macro](https://appfire.atlassian.net/wiki/spaces/RUN/pages/73074547)
- [Scripting for Confluence](https://appfire.atlassian.net/wiki/spaces/SCRP/overview) for one of the scripting macros, this example uses the [Groovy macro](https://appfire.atlassian.net/wiki/spaces/SCRP/pages/73728611)

# Run Macro Configuration

- Likely you will want to select **Automatically render body on display** (autoRun) so the table will be displayed with the default columns initially
- Add a checklistfieldcalled**columns **to the **Replace field list** (replace) that contains pairs matching column numbers to column names

> Macro (table-plus)
> 
> | **Description** | **Example** |
> | --- | --- |
> | Add a checklist field called **columns **to the **Replace field list** (replace) that contains name/value pairs matching column numbers to column names | columns:'1,2,3':Column selection:checkbox:1:1:A:2:B:3:C:4:D:5:E |
> | Likely you will want to select **Automatically render body on display** (autoRun) so the table will be displayed with the default columns initially | select **Automatically render body on display ** |

![image](media://ebf21099-6cce-4af9-9d40-a9a0642ead2b)

# Script

The script will need to be customized for your specific use. This is just a simple example. The **groovy** macro needs to set the **Output format** (output) to **wiki**.

```groovy
def includePage = 'Examples:table page'   // customize to point to your SPACE:Page title
def columnTypes = ['S','S','S','S','S']   // customize to set the default column types for all columns
def selectedColumns = '$columns'.split(',') // assumes run macro is configured using the columns replacement variable name
def moreTablePlusParameters = ''  // customize if you need some additional table plus parameters - must be in standard wiki parameter notation!
 
// For each column that was NOT selected, replace the default column type for that entry to hide
for (int i = 1; i <= columnTypes.size(); i++) {
    if (!selectedColumns.contains(i.toString())) {
        columnTypes[i - 1] = 'H'
    }
}

// Build the wiki markup for the include page 
def StringBuilder builder = new StringBuilder()
builder.append("{table-plus:columnTypes=${listToSeparatedString(columnTypes)}|${moreTablePlusParameters}}").append('\n')
builder.append("{include:${includePage}}").append('\n')
builder.append('{table-plus}')
 
out.print(builder.toString())
 
def listToSeparatedString(list) {
    StringBuilder builder = new StringBuilder()
    list.each { element ->
       builder.append("'").append(element).append("',")
    }
    return builder.toString()
} 
```