fix(data_table): resolve blank cells for non-camelCase column keys#6111
fix(data_table): resolve blank cells for non-camelCase column keys#6111zain2983 wants to merge 2 commits intoreflex-dev:mainfrom
Conversation
Greptile OverviewGreptile SummaryFixes blank cells in
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant DataTable
participant GridJS
User->>DataTable: Create with data (runtime Var) + columns (string list)
DataTable->>DataTable: _render() called
alt columns is LiteralVar with list
DataTable->>DataTable: Transform strings to {id, name} dicts
Note over DataTable: {"id": "Route", "name": "Route"}
else columns already dicts or non-LiteralVar
DataTable->>DataTable: Leave columns unchanged
end
DataTable->>GridJS: Pass transformed columns + data
GridJS->>GridJS: Use explicit id, skip camelCase inference
GridJS->>User: Render table with correct keys
|
| # 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 | ||
| ]) |
There was a problem hiding this comment.
Transformation only applies to LiteralVar. Verify runtime Var[list[str]] columns don't need the same fix
Prompt To Fix With AI
This is a comment left during a code review.
Path: reflex/components/gridjs/datatable.py
Line: 130:137
Comment:
Transformation only applies to `LiteralVar`. Verify runtime `Var[list[str]]` columns don't need the same fix
How can I resolve this? If you propose a fix, please make it concise.| # ----------------------------- | ||
| # Component Props | ||
| # ----------------------------- | ||
| data: Any # The data to display (list of lists or DataFrame) | ||
| columns: Var[Sequence] # Columns to display (optional if using DataFrame) | ||
| search: Var[bool] # Enable search | ||
| sort: Var[bool] # Enable sorting | ||
| resizable: Var[bool] # Enable column resizing | ||
| pagination: Var[bool | dict] # Enable pagination |
There was a problem hiding this comment.
these should not be reformatted; our doc generator specifically looks for comments preceeding props, so if you write it like this, our doc generator breaks
| # ----------------------------- | ||
| # Component creation | ||
| # ----------------------------- |
There was a problem hiding this comment.
reflex code style avoids these kind of fancy block comments
|
|
||
| # The annotation should be provided if data is a computed var. We need this to know how to | ||
| # render pandas dataframes. | ||
| # 1️⃣ Ensure computed Vars have type annotations |
There was a problem hiding this comment.
Remove the emoji from the comments
| self.columns = self.columns._replace( | ||
| _js_expr=( | ||
| f"{self.columns._js_expr}.map(" | ||
| "(col) => typeof col === 'string' " | ||
| "? ({ id: col, name: col }) " | ||
| ": col)" | ||
| ), | ||
| _var_type=list[Any], | ||
| ) |
There was a problem hiding this comment.
prefer to use Var Operations to construct the javascript expression
self.columns = self.columns.foreach(
lambda col: rx.cond(col.js_type() == 'string', {"id": col, "name": col}, col)
)The code it generates is not as "pretty", but it's more likely to remain functional as the framework evolves and the code generation changes.
| "reflex/components/recharts/polar.pyi": "ad24bd37c6acc0bc9bd4ac01af3ffe49", | ||
| "reflex/components/recharts/recharts.pyi": "c41d19ab67972246c574098929bea7ea", | ||
| "reflex/components/sonner/toast.pyi": "3c27bad1aaeb5183eaa6a41e77e8d7f0" | ||
| "reflex/components/gridjs/datatable.pyi": "e1f34ade3873a931770da4a35586f298" |
There was a problem hiding this comment.
the other hashes in this file are important too, only the changed files should be updated here
fix(data_table): resolve blank cells for non-camelCase column keys (#6108)
All Submissions:
Type of change
Changes To Core Features:
Description
When
rx.data_tablereceivesdataas a runtimeVarandcolumnsas a static list of strings, any column key that isn't already fully lowercase renders with blank cells.This happens because Grid.js infers each column's lookup
idby camelCasing the column name string. So a key like"Route"gets inferred as"route", which no longer matches the actual key in the data. Sincedatais a runtimeVar, the keys aren't available at build time, so normalising columns alone can't fix it.The fix converts each plain column string into the
{ id, name }object format that Grid.js also supports. Whenidis set explicitly, Grid.js skips the camelCase inference entirely and uses it directly as the lookup key. This ensures the key always matches regardless of casing. Columns already in object format are left untouched, so this is fully backward-compatible.Closes #6108