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

Identify column by name in renderer rather than index. #487

Open
jobinnthomas opened this issue Mar 7, 2024 · 0 comments
Open

Identify column by name in renderer rather than index. #487

jobinnthomas opened this issue Mar 7, 2024 · 0 comments

Comments

@jobinnthomas
Copy link

jobinnthomas commented Mar 7, 2024

In below code example, is there a way to do something where based on the cell column name, something is done. In the example below the column index is used.

I need to identify if a certain column name is present and do something. I dont want to do it by column index.
If you could also describe how I could look this up myself in the code, that would help me in future.

How can i troubleshoot these vegaexpression in ipydatagrid. Right now, I have no way to setup a breakpoint or print anything. Could you give some guidance on this?

My psudo-code below (wouldnt work but i need something similar)

renderer = TextRenderer(
    background_color=VegaExpr(
        "cell.colum_name == 'column 1' ? 'limegreen' : 'pink'"
    )

Example (that runs fine)


import pandas as pd
from ipydatagrid import DataGrid, TextRenderer, VegaExpr

df = pd.DataFrame(
    {
        "column 1": [{"key": 11}, ["berry", "apple", "cherry"]],
        "column 2": [["berry", "berry", "cherry"], {"key": 10}],
    }
)

renderer = TextRenderer(
    background_color=VegaExpr(
        "cell.value[1] == 'berry' && cell.metadata.data['column 1']['key'] == 11 ? 'limegreen' : 'pink'"
    )
)

DataGrid(
    df,
    layout={"height": "100px"},
    base_column_size=150,
    default_renderer=renderer,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant