Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions reflex/components/gridjs/datatable.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,14 @@ def _render(self) -> Tag:
self.columns = LiteralVar.create(data["columns"])
self.data = LiteralVar.create(data["data"])

# If columns is a list of strings convert to list of dicts with id and name keys
if isinstance(self.columns, LiteralVar) and isinstance(
self.columns._var_value, list
):
self.columns = LiteralVar.create([
{"id": col, "name": col} if isinstance(col, str) else col
for col in self.columns._var_value
])
Comment on lines +130 to +137
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix only applies to static columns (LiteralVar). Runtime Var columns with string values would still face the same camelCase issue. Consider handling both cases:

Suggested change
# If columns is a list of strings convert to list of dicts with id and name keys
if isinstance(self.columns, LiteralVar) and isinstance(
self.columns._var_value, list
):
self.columns = LiteralVar.create([
{"id": col, "name": col} if isinstance(col, str) else col
for col in self.columns._var_value
])
# If columns is a list of strings convert to list of dicts with id and name keys
if isinstance(self.columns, LiteralVar) and isinstance(
self.columns._var_value, list
):
self.columns = LiteralVar.create([
{"id": col, "name": col} if isinstance(col, str) else col
for col in self.columns._var_value
])
elif isinstance(self.columns, Var) and types.typehint_issubclass(self.columns._var_type, list):
# For runtime Vars, transform at runtime using JS map
self.columns = self.columns._replace(
_js_expr=f"{self.columns._js_expr}.map((col) => typeof col === 'string' ? {{id: col, name: col}} : col)",
)
Prompt To Fix With AI
This is a comment left during a code review.
Path: reflex/components/gridjs/datatable.py
Line: 130:137

Comment:
Fix only applies to static columns (`LiteralVar`). Runtime `Var` columns with string values would still face the same camelCase issue. Consider handling both cases:

```suggestion
        # If columns is a list of strings convert to list of dicts with id and name keys
        if isinstance(self.columns, LiteralVar) and isinstance(
            self.columns._var_value, list
        ):
            self.columns = LiteralVar.create([
                {"id": col, "name": col} if isinstance(col, str) else col
                for col in self.columns._var_value
            ])
        elif isinstance(self.columns, Var) and types.typehint_issubclass(self.columns._var_type, list):
            # For runtime Vars, transform at runtime using JS map
            self.columns = self.columns._replace(
                _js_expr=f"{self.columns._js_expr}.map((col) => typeof col === 'string' ? {{id: col, name: col}} : col)",
            )
```

How can I resolve this? If you propose a fix, please make it concise.


# Render the table.
return super()._render()