Column Definitions

Setting the column_definitions parameter to preconfigure the formatting of your data requires a Mito Enterprise License.

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.

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.

  • 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.

  • 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.

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

Filter Conditions Reference List

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.

Column Data Type
Filter Conditions

Number

number_exactly

number_not_exactly

greater

greater_than_or_equal

less

less_than_or_equal

number_lowest

number_highest

String

contains

string_does_not_contain

string_exactly

string_not_exactly

string_starts_with

string_ends_with

string_contains_case_insensitive

Dates

datetime_exactly

datetime_not_exactly

datetime_greater

datetime_greater_than_or_equal

datetime_less

datetime_less_than_or_equal

Boolean

boolean_is_true

boolean_is_false

Any Data Type

empty

not_empty

most_frequent

least_frequent

More Examples

Applying conditional formatting to a single dataframe

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

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' 
                }] 
            },
        ],
    ]
)

Last updated

© Mito