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

ui.aggrid does not show values if there is a period in the column name #1417

Closed
dashorty opened this issue Aug 14, 2023 · 9 comments
Closed
Assignees
Labels
documentation Improvements or additions to documentation
Milestone

Comments

@dashorty
Copy link

Description

If there is a period in the Name column, the value of this column is not displayed.
I noticed when I wanted to normalize a JSON with panda.

Here is an example:

import pandas as pd
from nicegui import ui


data = [
    {"id": 1, "name": {"first": "Coleen", "last": "Volk"}},
    {"name": {"given": "Mark", "family": "Regner"}},
    {"id": 2, "name": "Faye Raker"},
]

df = pd.json_normalize(data)
df2 = pd.json_normalize(data, sep="_")

ui.label("with period in the column name")
ui.aggrid.from_pandas(df)
ui.label("without period in the column name (sep=\"_\")")
ui.aggrid.from_pandas(df2)

ui.run(show=False)

2023-08-14 12 05 09 localhost 59e593e7cf84

@falkoschindler
Copy link
Contributor

Thanks for reporting this issue, @dashorty!
I didn't even know that you can - in principle - use nested dictionaries for defining row data. But apparently we can't use column IDs with dots like in the following example:

ui.aggrid({
    'columnDefs': [{'headerName': 'First name', 'field': 'name.first'}],
    'rowData': [{'name.first': 'Alice'}],
})

That's because AG Grid tries to access rowData[0]['name']['first'] instead of rowData[0]['name.first'].

I'm not sure if this is a bug in NiceGUI or rather a limitation of AG Grid. Maybe NiceGUI should warn about column IDs containing dots? What do you think, @dashorty? Do you have an idea in mind how to approach this?

@dashorty
Copy link
Author

I think a warning at runtime and/or a note in the documentation would be sufficient.

@falkoschindler
Copy link
Contributor

Ok, commit c6ad97a adds such a warning.
Commit 3f4f2cf adds a demo with complex objects in an AG Grid.

@falkoschindler falkoschindler added this to the 1.3.10 milestone Aug 14, 2023
@falkoschindler falkoschindler added the documentation Improvements or additions to documentation label Aug 14, 2023
@falkoschindler falkoschindler self-assigned this Aug 14, 2023
@firai
Copy link

firai commented Aug 16, 2023

According to https://stackoverflow.com/questions/58772051, it's possible to show field names with dots by suppressing Aggrid's parsing for nested structures

@falkoschindler
Copy link
Contributor

Thanks for the hint, @firai!
So should we simply set suppressFieldDotNotation instead of showing a warning?

@firai
Copy link

firai commented Aug 16, 2023

So should we simply set suppressFieldDotNotation instead of showing a warning?

It seems to me that having dots in the field names would be much more common than trying to display nested json structures, so I would think so. But as soon as I say that, I'm sure we'll get this: https://xkcd.com/1172/

@falkoschindler
Copy link
Contributor

Ok, in 325dfcd I set the suppressFieldDotNotation option instead of showing a warning. That should work in basically all cases.
I also added the possibility to pass additional options to the from_pandas method. So the user could overwrite this flag.

@firai
Copy link

firai commented Aug 17, 2023

Does the complex object demo that you added need to explicitly set the flag to false then?

@falkoschindler
Copy link
Contributor

@firai I don't think so, because it doesn't use from_pandas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants