Column Grouping

Group related columns under flat or nested headers with ColumnGroup and group_columns.

Column Grouping

Group related columns under flat or nested headers with ColumnGroup and group_columns.

Source: usage.py::build_group_columns_code().

table = (
    dmdt.DataTable(
        id="group-columns-table",
        data=EMPLOYEES[:6],
        columns=GROUP_COLUMNS_BASE_COLUMNS,
        paginationMode="none",
    )
    .update_layout(radius="lg", withTableBorder=True, withColumnBorders=True)
    .group_columns(
        dmdt.ColumnGroup(
            "profile",
            title="Profile",
            style={"fontStyle": "italic"},
            groups=[
                dmdt.ColumnGroup("identity", title="Identity", columns=["name", "role"]),
                dmdt.ColumnGroup("organization", title="Organization", columns=["team", "location"]),
            ],
        ),
        dmdt.ColumnGroup(
            "performance",
            title="Performance",
            textAlign="center",
            style={"backgroundColor": "var(--mantine-color-blue-0)"},
            columns=["deliveryScore", "status", "salary"],
        ),
    )
    .group_columns(
        selector="profile",
        style={"backgroundColor": "var(--mantine-color-gray-0)"},
    )
    .group_columns(
        selector="organization",
        textAlign="center",
        style={"color": "var(--mantine-color-blue-6)"},
    )
)