Skip to content

Commit

Permalink
Fixing virtualRowData by adding rowModelType as default `'clientS…
Browse files Browse the repository at this point in the history
…ide'`

- added test for sort, and filter to update `virtualRowData`
  • Loading branch information
BSd3v committed Feb 22, 2023
1 parent 168aa20 commit 5042597
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/components/AgGrid.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ DashAgGrid.defaultProps = {
persistence_type: 'local',
suppressDragLeaveHidesColumns: true,
dangerously_allow_code: false,
rowModelType: 'clientSide',
};
DashAgGrid.propTypes = {
/********************************
Expand Down
82 changes: 82 additions & 0 deletions tests/test_virtual_row_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from dash import Dash, html, dcc, Output, Input
import dash_ag_grid as dag

from . import utils


def test_vr001_virtual_row_data(dash_duo):
app = Dash(__name__)

rowData = [
{"make": "Toyota", "model": "Celica", "price": 35000},
{"make": "Ford", "model": "Mondeo", "price": 32000},
{"make": "Porsche", "model": "Boxter", "price": 72000},
]

columnDefs = [
{"headerName": "Make", "field": "make", "sortable": True},
{"headerName": "Model", "field": "model"},
{"headerName": "Price", "field": "price"},
]

app.layout = html.Div(
[
dcc.Markdown(
"Try filtering the data in the grid using the inline filters (click the hamburger menu in each column). Though the data is still in `rowData`, you can view the virtual row data in callbacks by watching the `virtualRowData` property."
),
dag.AgGrid(
id="grid",
columnDefs=columnDefs,
rowData=rowData,
defaultColDef={
"sortable": True,
"filter": True,
"floatingFilter": True
},
),
html.Div(id="data-after-filter"),
]
)

@app.callback(
Output("data-after-filter", "children"),
Input("grid", "virtualRowData"),
)
def get_virtual_data(virtual):
return str(virtual)

dash_duo.start_server(app)

grid = utils.Grid(dash_duo, "grid")

dash_duo.wait_for_text_to_equal('#data-after-filter', "[{'make': 'Toyota', 'model': 'Celica', 'price': 35000}, "
"{'make': 'Ford', 'model': 'Mondeo', 'price': 32000}, "
"{'make': 'Porsche', 'model': 'Boxter', 'price': 72000}]")

grid.set_filter(0, "F")

dash_duo.wait_for_text_to_equal('#data-after-filter', "[{'make': 'Ford', 'model': 'Mondeo', 'price': 32000}]")

grid.set_filter(0, "")

dash_duo.wait_for_text_to_equal('#data-after-filter', "[{'make': 'Toyota', 'model': 'Celica', 'price': 35000}, "
"{'make': 'Ford', 'model': 'Mondeo', 'price': 32000}, "
"{'make': 'Porsche', 'model': 'Boxter', 'price': 72000}]")

grid.get_header_cell(0).click()

dash_duo.wait_for_text_to_equal('#data-after-filter', "[{'make': 'Ford', 'model': 'Mondeo', 'price': 32000}, "
"{'make': 'Porsche', 'model': 'Boxter', 'price': 72000},"
" {'make': 'Toyota', 'model': 'Celica', 'price': 35000}]")

grid.get_header_cell(0).click()

dash_duo.wait_for_text_to_equal('#data-after-filter', "[{'make': 'Toyota', 'model': 'Celica', 'price': 35000}, "
"{'make': 'Porsche', 'model': 'Boxter', 'price': 72000}, "
"{'make': 'Ford', 'model': 'Mondeo', 'price': 32000}]")

grid.get_header_cell(0).click()

dash_duo.wait_for_text_to_equal('#data-after-filter', "[{'make': 'Toyota', 'model': 'Celica', 'price': 35000}, "
"{'make': 'Ford', 'model': 'Mondeo', 'price': 32000}, "
"{'make': 'Porsche', 'model': 'Boxter', 'price': 72000}]")

0 comments on commit 5042597

Please sign in to comment.