from dash import Dash, html, dcc, Input, Output, callback
import dash_mantine_components as dmc
import dash
import dash_ag_grid as dag
import pandas as pd
app = Dash(
__name__,
external_stylesheets=dmc.styles.ALL,
suppress_callback_exceptions=True,
)
df = pd.DataFrame({
'Column 1': [1, 2, 3],
'Select': [None, None, None]
})
labels = ["Pandas", "NumPy", "TensorFlow", "PyTorch", "Pydantic", "Polars"]
select_component = dmc.Select(
data=labels,
placeholder="Type 'p' for 'Pandas' and hit Tab. Try with Enter too",
selectFirstOptionOnChange=True,
autoSelectOnBlur=False,
clearSearchOnFocus=True,
searchable=True,
)
select_component_with_autoselect = dmc.Select(
data=labels,
placeholder="Type 'p' for 'Pandas' and hit Tab. Try with Enter too",
selectFirstOptionOnChange=True,
autoSelectOnBlur=True,
clearSearchOnFocus=True,
searchable=True,
)
columnDefs_noauto = [
{ "field": "Column 1", "headerName": "id", "maxWidth": 50},
{
"field": "Select",
"editable":True,
'cellEditor': {'function': 'AllFunctionalComponentEditors'},
'cellEditorParams': {'component':select_component},
'cellEditorPopup': True,
"flex": 1
},
]
columnDefs_withauto = [
{ "field": "Column 1", "headerName": "id", "maxWidth": 50},
{
"field": "Select",
"editable":True,
'cellEditor': {'function': 'AllFunctionalComponentEditors'},
'cellEditorParams': {'component':select_component_with_autoselect},
'cellEditorPopup': True,
"flex": 1
},
]
columnDefs_RichSelect = [
{ "field": "Column 1", "headerName": "id", "maxWidth": 50},
{
"field": "RichSelect",
"editable":True,
"cellEditor": "agRichSelectCellEditor",
"cellEditorParams": {
"values": labels,
"searchType": "matchAny",
"allowTyping": True,
"filterList": True,
"highlightMatch": True,
"valueListMaxHeight": 220,
},
"flex": 1
},
]
ag_grid_0 = dag.AgGrid(
columnDefs=columnDefs_noauto,
rowData=df.to_dict('records'),
dashGridOptions={'singleClickEdit': True},
style ={"height":"200px"}
)
ag_grid_1 = dag.AgGrid(
columnDefs=columnDefs_withauto,
rowData=df.to_dict('records'),
dashGridOptions={'singleClickEdit': True},
style ={"height":"200px"}
)
ag_grid_2 = dag.AgGrid(
columnDefs=columnDefs_withauto,
rowData=df.to_dict('records'),
dashGridOptions={
"singleClickEdit": True,
"enterNavigatesVertically":True,
"enterNavigatesVerticallyAfterEdit":True},
style ={"height":"200px"}
)
ag_grid_3 = dag.AgGrid(
enableEnterpriseModules=True,
columnDefs=columnDefs_RichSelect,
rowData=df.to_dict('records'),
dashGridOptions={
"singleClickEdit": True,
"enterNavigatesVertically":True,
"enterNavigatesVerticallyAfterEdit":True},
style ={"height":"200px"}
)
def app_layout():
return dmc.MantineProvider(
children=dmc.Stack([
dmc.Text("dmc.Select without AutoSelect"),
select_component,
dmc.Text("dmc.Select with AutoSelect"),
select_component_with_autoselect,
dmc.Text("Ag Grid dmc.Select, no AutoSelect"),
ag_grid_0,
dmc.Text("Ag Grid dmc.Select, with AutoSelect"),
ag_grid_1,
dmc.Text("Ag Grid dmc.Select, with AutoSelect, with Enter Vertically:"),
ag_grid_2,
dmc.Text("Ag Grid RichSelect, with Enter Vertically:"),
ag_grid_3,
]),
id="mantine-provider",
)
app.layout = app_layout
if __name__ == "__main__":
app.run(debug=True)