Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Links "DE#nnn" prior to version 2.0 point to the Dash Enterprise closed-source D
### Added
- [#453](https://github.com/plotly/dash-ag-grid/pull/453) Test for changelog entry
- [#455](https://github.com/plotly/dash-ag-grid/pull/455) Added support for dynamic `detailCellRendererParams` in Master/Detail, including dynamic detail-grid column definitions.
- [#468](https://github.com/plotly/dash-ag-grid/issues/468) Support passing a function to the grid option `processUnpinnedColumns`.

### Changed
- [#452](https://github.com/plotly/dash-ag-grid/pull/452)
Expand Down
3 changes: 3 additions & 0 deletions src/lib/utils/propCategories.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export const GRID_MAYBE_FUNCTIONS = {
sendToClipboard: 1,
processDataFromClipboard: 1,

// Columns
processUnpinnedColumns: 1,

// Exporting
getCustomContentBelowRow: 1,
shouldRowBeSkipped: 1,
Expand Down
9 changes: 9 additions & 0 deletions tests/assets/dashAgGridFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,15 @@ dagfuncs.dateFilterComparator = (filterLocalDateAtMidnight, cellValue) => {

// END test_custom_filter.py

// FOR test_column_pinning.py
dagfuncs.unpinAllButFirstColumn = (params) => {
const {api} = params;
// columns contains the columns AgGrid would like to unpin, but we can override that by returning
// a different set of columns. In this case, we will unpin all columns except the first column
return api.getColumns().filter((col, index) => index > 0 && col.isPinned());
}
// END test_column_pinning.py

// FOR test_quick_filter.py
dagfuncs.quickFilterMatcher = (quickFilterParts, rowQuickFilterAggregateText) => {
return quickFilterParts.every(part => rowQuickFilterAggregateText.match(part));
Expand Down
56 changes: 56 additions & 0 deletions tests/test_column_pinning.py
Comment thread
datenzauberai marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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."""

# Make sure that the pinned columns will not fit in the available viewport space and
# the processUnpinnedColumns function will be called.
window_width = 1280
dash_duo.driver.set_window_size(window_width, 720)

column_width = 300
column_count = int(window_width / column_width) + 1
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",
"width": column_width,
}
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")
Comment thread
datenzauberai marked this conversation as resolved.
for col_idx in range(1, column_count):
grid.wait_for_pinned_column(col_id=f"COL_{col_idx}", pin_state="scrolling")

39 changes: 35 additions & 4 deletions tests/utils.py
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
Expand Down Expand Up @@ -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")
Comment thread
datenzauberai marked this conversation as resolved.

def _header_class_for_pin_state(self, pin_state: Literal["left", "right", "scrolling"]):
Comment thread
datenzauberai marked this conversation as resolved.
"""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"] = "left"):
"""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"] = "left",
) -> 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):
Expand Down
Loading