Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aggrid cannot set group header #94

Open
CrystalWindSnake opened this issue Jan 19, 2024 · 2 comments
Open

aggrid cannot set group header #94

CrystalWindSnake opened this issue Jan 19, 2024 · 2 comments
Labels
question Further information is requested

Comments

@CrystalWindSnake
Copy link
Owner

aggrid in nicegui allows grouped table headers, but not in the bi module in ex4nicegui.

grid = ui.aggrid(
    {
        "defaultColDef": {"flex": 1},
        "columnDefs": [
            {
                "headerName": "xxxx",
                "children": [
                    {
                        "field": "name",
                    },
                    {
                        "field": "age",
                    },
                ],
            },
            {
                "field": "parent",
            },
        ],
        "rowData": [
            {"name": "Alice", "age": 18, "parent": "David"},
            {"name": "Bob", "age": 21, "parent": "Eve"},
            {"name": "Carol", "age": 42, "parent": "Frank"},
        ],
        "rowSelection": "multiple",
    }
).classes("max-h-40")


ds = bi.data_source(
    pd.DataFrame(
        {"name": "Alice", "age": 18, "parent": "David"},
        {"name": "Bob", "age": 21, "parent": "Eve"},
        {"name": "Carol", "age": 42, "parent": "Frank"},
    )
)

ds.ui_aggrid(
    options={
        "columnDefs": [
            {
                "headerName": "xxxx",
                "children": [
                    {
                        "field": "name",
                    },
                    {
                        "field": "age",
                    },
                ],
            },
            {
                "field": "parent",
            },
        ],
    }
)
@CrystalWindSnake CrystalWindSnake added the question Further information is requested label Jan 19, 2024
@CrystalWindSnake
Copy link
Owner Author

Currently options can be modified by accessing the native element

ds = bi.data_source(
    pd.DataFrame(
        {"name": "Alice", "age": 18, "parent": "David"},
        {"name": "Bob", "age": 21, "parent": "Eve"},
        {"name": "Carol", "age": 42, "parent": "Frank"},
    )
)

table = ds.ui_aggrid()


col_defs: List[Dict] = table.element.options["columnDefs"]

#  Remove the configuration of name and age.
col_defs.pop(0)
col_defs.pop(0)

# Insert a grouping of name and age
col_defs.insert(
    0,
    {
        "headerName": "xxxx",
        "children": [
            {
                "field": "name",
            },
            {
                "field": "age",
            },
        ],
    },
)

@CrystalWindSnake
Copy link
Owner Author

Perhaps a way to tweak the configuration could be provided

ds.ui_aggrid().adjust_column_defs(
    {
        #  0 means put in the first column
        0: {
            "headerName": "xxxx",
            "children": [
                {
                    "field": "name",
                },
                {
                    "field": "age",
                },
            ],
        },
    },
    # Remove some columns
    remove=["name", "age"],
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant