-
Notifications
You must be signed in to change notification settings - Fork 43
Support processUnpinnedColumns #470
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
base: v35
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import dash_ag_grid as dag | ||
| from dash import Dash, html, dcc | ||
| from . import utils | ||
| import uuid | ||
|
|
||
|
|
||
| def test_cd001_process_unpinned_columns(dash_duo): | ||
| """ Test that the processUnpinnedColumns function is called when the available viewport space is exceeded and the right most columns are unpinned.""" | ||
|
|
||
| column_count = 10 | ||
| row_count = 10 | ||
| row_data = [ | ||
| {f"COL_{col_idx}": uuid.uuid4().hex for col_idx in range(column_count)} for _ in range(row_count) | ||
| ] | ||
|
|
||
| app = Dash(__name__) | ||
| column_defs = [ | ||
| { | ||
| "field": col, | ||
| "pinned": "left" | ||
| } | ||
| for col in row_data[0].keys() | ||
| ] | ||
|
|
||
| app.layout = html.Div( | ||
| [ | ||
| dcc.Markdown( | ||
| "This grid uses a javascript function to make sure," | ||
| " that the right most columns are unpinned when the available viewport space is exceeded." | ||
| ), | ||
| dag.AgGrid( | ||
| columnDefs=column_defs, | ||
| rowData=row_data, | ||
| id="grid", | ||
| dashGridOptions={ | ||
| "processUnpinnedColumns": {"function": "unpinAllButFirstColumn(params)"}, | ||
| } | ||
| ), | ||
| ], | ||
| style={"margin": 20}, | ||
| ) | ||
| dash_duo.start_server(app) | ||
|
|
||
| grid = utils.Grid(dash_duo, "grid") | ||
|
|
||
| grid.wait_for_pinned_column(col_id="COL_0", pin_state="left") | ||
| grid.wait_for_pinned_column(col_id="COL_1", pin_state="scrolling") | ||
| grid.wait_for_pinned_column(col_id="COL_4", pin_state="scrolling") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| from typing import Literal | ||
|
|
||
| from selenium.webdriver.common.action_chains import ActionChains | ||
|
|
||
| from dash.testing.wait import until | ||
|
|
@@ -44,11 +46,40 @@ def _wait_for_count(self, selector, expected, description): | |
| raise ValueError(f"found {len(els)} {description}, expected {expected}") | ||
|
|
||
| def wait_for_pinned_cols(self, expected): | ||
| # TODO: is there a pinned right? | ||
| self.wait_for_pinned_column_count(expected, pin_state="left") | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I frowned upon refactoring all calls to |
||
|
|
||
| def _header_class_for_pin_state(self, pin_state: Literal["left", "right", "scrolling"]): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The header classes will change with AgGrid 36 (.ag-grid-pinned-left-cells .ag-grid-scrolling-cells .ag-grid-pinned-right-cells) so I thought it would be good to already locate this in one method. |
||
| """Return the appropriate header class for the given pin state.""" | ||
| if pin_state == "scrolling": | ||
| return "ag-header-viewport" | ||
| elif pin_state == "left": | ||
| return "ag-pinned-left-header" | ||
| elif pin_state == "right": | ||
| return "ag-pinned-right-header" | ||
| else: | ||
| raise ValueError(f"Invalid pin_state: {pin_state}") | ||
|
|
||
| def wait_for_pinned_column_count(self, expected_count, pin_state: Literal["left", "right", "scrolling"]): | ||
| """Wait for the number of columns in the specified pin state to match the expected count.""" | ||
| header_class = self._header_class_for_pin_state(pin_state) | ||
| self._wait_for_count( | ||
| f'#{self.id} .ag-pinned-left-header [aria-rowindex="1"] .ag-header-cell', | ||
| expected, | ||
| "pinned_cols", | ||
| f'#{self.id} .{header_class} [aria-rowindex="1"] .ag-header-cell', | ||
| expected_count, | ||
| f"pinned_cols '{pin_state}'", | ||
| ) | ||
|
|
||
| def wait_for_pinned_column( | ||
| self, | ||
| col_id: str, | ||
| pin_state: Literal["left", "right", "scrolling"], | ||
| ) -> None: | ||
| """Wait for a column to be in the specified pin state.""" | ||
| header_class = self._header_class_for_pin_state(pin_state) | ||
|
|
||
| self._wait_for_count( | ||
| f'#{self.id} .{header_class} [aria-rowindex="1"] .ag-header-cell[col-id="{col_id}"]', | ||
| 1, | ||
| f"column '{col_id}' pinned '{pin_state}'", | ||
| ) | ||
|
|
||
| def wait_for_viewport_cols(self, expected): | ||
|
|
||
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.
This would fail without unpinAllButFirstColumn, because default AgGrid behaviour would be to start unpinning at COL_0.