# Column Definitions

{% hint style="info" %}
Setting the `column_definitions` parameter to preconfigure the formatting of your data requires a [Mito Enterprise License](https://www.trymito.io/plans).&#x20;
{% endhint %}

### Why use the column\_definitions parameter?

The `column_definitions` parameter allows you to preconfigure the format of columns displayed in the Mito Spreadsheet. They're particularly useful when you need to apply conditional formatting to columns so your app users can instantly see informative data immedietly after loading your app. &#x20;

### Column Definitions Usage

The `column_conditions` parameter allows users to define conditional formatting rules for specific columns in specific dataframes displayed spreadsheet.

The `column_conditions` is a list of formatting configurations applied to each sheet. &#x20;

* **columns**:  Specifies the columns names to apply the conditional formatting rule to.
* **conditional\_formats**: Specifies the conditional formatting rules for the specified columns.
* **filters**: Each filter is a pair of `condition`  and `value`. For example, if the `condition` is 'greater' and the value is 5, the applied font\_color and background\_color will be applied to all cells in the specific column with a value greater than 5. [See a full list available conditions here](#filter-conditions-reference-list).&#x20;
* **font\_color**: The Hex string representation the font should be displayed in if the cell meets the required condition. A valid conditional format must have at least a font\_color and/or background\_color.
* **backgrond\_color:** The Hex string representation the cell background should be colored in if the cell meets the required condition. A valid conditional format must have at least a font\_color and/or background\_color.

#### Example Usage

The below `column_definitions` displays applies conditional formatting to columns "A" and "B" in the first dataframe inside the spreadsheet.&#x20;

```python
spreadsheet(
    df1, 
    column_definitions=[
        [
            {
                'columns': ['A', 'B'],
                'conditional_formats': [{
                    'filters': [{'condition': 'greater', 'value': 5}], 
                    'font_color': '#c30010', 
                    'background_color': '#ffcbd1' 
                }] 
            }
        ]
    ]
)
```

## Filter Conditions Reference List&#x20;

Below is the complete list of `conditions` available to be used in a conditional format filter. Take note that most filter conditions are only valid if applied to a column with the correct data type, except for the filter conditions labelled with `Any Data Type` at the bottom of the table.&#x20;

<table><thead><tr><th width="230">Column Data Type</th><th width="522">Filter Conditions</th></tr></thead><tbody><tr><td>Number</td><td><code>number_exactly</code></td></tr><tr><td></td><td><code>number_not_exactly</code></td></tr><tr><td></td><td><code>greater</code></td></tr><tr><td></td><td><code>greater_than_or_equal</code></td></tr><tr><td></td><td><code>less</code></td></tr><tr><td></td><td><code>less_than_or_equal</code></td></tr><tr><td></td><td><code>number_lowest</code></td></tr><tr><td></td><td><code>number_highest</code></td></tr><tr><td>String</td><td><code>contains</code></td></tr><tr><td></td><td><code>string_does_not_contain</code></td></tr><tr><td></td><td><code>string_exactly</code></td></tr><tr><td></td><td><code>string_not_exactly</code></td></tr><tr><td></td><td><code>string_starts_with</code></td></tr><tr><td></td><td><code>string_ends_with</code></td></tr><tr><td></td><td><code>string_contains_case_insensitive</code></td></tr><tr><td>Dates</td><td><code>datetime_exactly</code></td></tr><tr><td></td><td><code>datetime_not_exactly</code></td></tr><tr><td></td><td><code>datetime_greater</code></td></tr><tr><td></td><td><code>datetime_greater_than_or_equal</code></td></tr><tr><td></td><td><code>datetime_less</code></td></tr><tr><td></td><td><code>datetime_less_than_or_equal</code></td></tr><tr><td>Boolean</td><td><code>boolean_is_true</code></td></tr><tr><td></td><td><code>boolean_is_false</code></td></tr><tr><td>Any Data Type</td><td><code>empty</code></td></tr><tr><td></td><td><code>not_empty</code></td></tr><tr><td></td><td><code>most_frequent</code></td></tr><tr><td></td><td><code>least_frequent</code></td></tr></tbody></table>

## More Examples

#### Applying conditional formatting to a single dataframe

```python
spreadsheet(
    df1, 
    column_definitions=[
        [
            {
                'columns': ['A', 'B'],
                'conditional_formats': [{
                    'filters': [{'condition': 'greater', 'value': 5}], 
                    'font_color': '#c30010', 
                    'background_color': '#ffcbd1' 
                }] 
            }
        ]
    ]
)
```

#### Applying multiple conditional formatting rules to a single dataframe

```
spreadsheet(    
    df1, 
    column_definitions=[
        [
            {
                'columns': ['A'],
                'conditional_formats': [{
                    'filters': [{'condition': 'greater', 'value': 5}], 
                    'font_color': '#c30010', 
                    'background_color': '#ffcbd1' 
                }] 
            },
            {
                'columns': ['B'],
                'conditional_formats': [{
                    'filters': [{'condition': 'contains', 'value': 'invalid'}], 
                    'font_color': '#c30010', 
                    'background_color': '#ffcbd1' 
                }] 
            }
        ]
    ]
) 
```

#### Applying conditional formatting to multiple dataframes

```python
spreadsheet(
    df1, 
    df2
    column_definitions=[
        [
            {
                'columns': ['A', 'B'],
                'conditional_formats': [{
                    'filters': [{'condition': 'greater', 'value': 5}], 
                    'font_color': '#c30010', 
                    'background_color': '#ffcbd1' 
                }] 
            },
        ],
        [
            {
                'columns': ['C', 'D'],
                'conditional_formats': [{
                    'filters': [{'condition': 'less', 'value': 0}], 
                    'font_color': '#c30010', 
                    'background_color': '#ffcbd1' 
                }] 
            },
        ],
    ]
)
```

##
