-
Notifications
You must be signed in to change notification settings - Fork 1.7k
docs: enterprise component field notes (ag-grid, map, react flow) #6781
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
Open
amsraman
wants to merge
2
commits into
main
Choose a base branch
from
docs/enterprise-field-notes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| --- | ||
| meta_description: "Enable master-detail rows in AG Grid with Reflex. Expand rows to reveal a nested detail grid backed by per-row data, configured entirely in Python." | ||
| title: Master Detail | ||
| --- | ||
|
|
||
| # Master Detail | ||
|
|
||
| Master-detail lets rows expand to show detailed information in a nested grid. Each master row carries its detail rows as a nested list, and an expandable column reveals them. | ||
|
|
||
| Three pieces are required: | ||
|
|
||
| 1. `master_detail=True` on the grid. | ||
| 2. A column with `"cell_renderer": "agGroupCellRenderer"`, which renders the expand/collapse arrows. | ||
| 3. `detail_cell_renderer_params` describing the detail grid's columns and how to extract the detail rows from the master row. | ||
|
|
||
| ```python | ||
| import reflex as rx | ||
| import reflex_enterprise as rxe | ||
|
|
||
|
|
||
| class MasterDetailState(rx.State): | ||
| master_data: list[dict] = [ | ||
| { | ||
| "id": 1, | ||
| "name": "Product A", | ||
| "category": "Electronics", | ||
| "price": 299.99, | ||
| "counts": [ # Detail rows for this master row | ||
| {"count": 10, "value": "Stock Level"}, | ||
| {"count": 5, "value": "Orders Today"}, | ||
| {"count": 25, "value": "Total Sales"}, | ||
| ], | ||
| }, | ||
| { | ||
| "id": 2, | ||
| "name": "Product B", | ||
| "category": "Clothing", | ||
| "price": 49.99, | ||
| "counts": [ | ||
| {"count": 50, "value": "Stock Level"}, | ||
| {"count": 12, "value": "Orders Today"}, | ||
| {"count": 78, "value": "Total Sales"}, | ||
| ], | ||
| }, | ||
| ] | ||
|
|
||
|
|
||
| column_defs = [ | ||
| { | ||
| "field": "id", | ||
| "header_name": "ID", | ||
| "width": 80, | ||
| "cell_renderer": "agGroupCellRenderer", # Required for expand/collapse | ||
| }, | ||
| {"field": "name", "header_name": "Product Name", "width": 150}, | ||
| {"field": "category", "header_name": "Category", "width": 120}, | ||
| { | ||
| "field": "price", | ||
| "header_name": "Price", | ||
| "width": 100, | ||
| "value_formatter": "params.value ? '$' + params.value.toFixed(2) : ''", | ||
| }, | ||
| ] | ||
|
|
||
| detail_cell_renderer_params = { | ||
| "detail_grid_options": { | ||
| "column_defs": [ | ||
| {"field": "count", "header_name": "Count"}, | ||
| {"field": "value", "header_name": "Description"}, | ||
| ] | ||
| }, | ||
| "get_detail_row_data": lambda params: rx.vars.function.FunctionStringVar( | ||
| "params.successCallback" | ||
| ).call(params.data.counts), | ||
| } | ||
|
|
||
|
|
||
| def master_detail_grid(): | ||
| return rxe.ag_grid( | ||
| id="master_detail_grid", | ||
| row_data=MasterDetailState.master_data, | ||
| column_defs=column_defs, | ||
| master_detail=True, | ||
| detail_cell_renderer_params=detail_cell_renderer_params, | ||
| width="100%", | ||
| height="500px", | ||
| ) | ||
| ``` | ||
|
|
||
| ## How Detail Rows Are Provided | ||
|
|
||
| `get_detail_row_data` follows AG Grid's asynchronous convention: the grid passes a `params` object containing the master row's `data` and a `successCallback` to invoke with the detail rows. The lambda above calls `params.successCallback` with the nested `counts` list of the expanded row. | ||
|
|
||
| The detail grid is a full AG Grid instance with its own `column_defs`, independent from the master grid's columns. | ||
|
|
||
| ## Static vs State Configuration | ||
|
|
||
| Both the column definitions and the detail renderer params can be plain module-level objects or state vars, depending on whether they need to change at runtime: | ||
|
|
||
| ```python | ||
| STATIC_DETAIL_PARAMS = { | ||
| "detail_grid_options": {"column_defs": [{"field": "count"}]}, | ||
| "get_detail_row_data": lambda params: rx.vars.function.FunctionStringVar( | ||
| "params.successCallback" | ||
| ).call(params.data.counts), | ||
| } | ||
|
|
||
|
|
||
| class State(rx.State): | ||
| # Dynamic variant: update these vars to reconfigure the grid | ||
| detail_cell_renderer_params: dict = STATIC_DETAIL_PARAMS | ||
|
greptile-apps[bot] marked this conversation as resolved.
Outdated
|
||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this dynamic variant is copied with
STATIC_DETAIL_PARAMSabove, the state var contains theget_detail_row_datalambda. Reflex state vars are serialized for the client; arbitrary callables inside a dict are not preserved, so the detail grid loses the callback and expanded rows cannot load. Keep renderer params with JS callbacks as module-level props or rebuild them in the component instead of storing them inrx.State.Useful? React with 👍 / 👎.