I am using ag grid and have filtering enabled. I have a button to clear all filters. This button is only enabled if there are any filters active. While I am typing in the filter, it loses focus. I did not have this problem with datatable. The problem also seems to go away without the Loading. dbc.spinner has the same problem as Loading. My min example was part of a much bigger more complex program. I have pared the program down to a simple example. When running the example, type an x in the filter for the first column and the filter will lose focus forcing a click in the filter to continue typing in the filter. The example almost always displays the issue for me. If it does not display the issue at first, delete what is in the filter and start typing again.
from dash import callback, Dash, dcc, html, Input, no_update, Output
import dash_ag_grid as dag
import dash_bootstrap_components as dbc
import pandas as pd
app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP], suppress_callback_exceptions=True,
meta_tags=[{'name': 'viewport', 'content': 'width=device-width, initial-scale=1.0'}])
dataframe = pd.DataFrame({'product_id': ['XYZ083-02ABC', 'NYZ082-02ABC', 'XYZ083-05ABC'],
'column_2_data': [2, 4, 6], 'column_3_data': [2, 4, 6], 'column_4_data': [2, 4, 6],
'column_5_data': [2, 4, 6], 'column_6_data': [2, 4, 6], 'column_7_data': [2, 4, 6],
'column_8_data': [2, 4, 6], 'column_9_data': [2, 4, 6], 'column_10_data': [2, 4, 6]})
default_col_def = {'filter': True,
'floatingFilter': True,
'resizable': True,
'sortable': True,
'editable': False,
'minWidth': 125,
'wrapHeaderText': True,
'autoHeaderHeight': True}
col_defs = [{'field': 'product_id', 'type' : None},
{'field': 'column_2_data', 'type': 'numericColumn'},
{'field': 'column_3_data', 'type': 'numericColumn'},
{'field': 'column_4_data', 'type': 'numericColumn'},
{'field': 'column_5_data', 'type': 'numericColumn'},
{'field': 'column_6_data', 'type': 'numericColumn'},
{'field': 'column_7_data', 'type': 'numericColumn'},
{'field': 'column_8_data', 'type': 'numericColumn'},
{'field': 'column_9_data', 'type': 'numericColumn'},
{'field': 'column_10_data', 'type': 'numericColumn'}]
datatable = dag.AgGrid(id="datatable",
columnDefs=col_defs,
defaultColDef=default_col_def,
rowData=dataframe.to_dict('records'),
dashGridOptions={'undoRedoCellEditing': True},
suppressDragLeaveHidesColumns=False,
persistence=True,
style={'resize': 'vertical', 'overflow': 'hidden'})
page = dcc.Loading(children=[dbc.Row(dbc.Col(html.Button(id="clear", n_clicks=0, children='Clear Filter', disabled=True),
)),
dbc.ListGroup(children=[dbc.ListGroupItem(datatable)], flush=True)])
app.layout = dbc.Container(dbc.Card(dbc.CardBody(page)),
fluid=True)
@callback(Output("datatable", 'filterModel'),
Input("clear", 'n_clicks'),
prevent_initial_call=True)
def clear_filter(n_clicks):
"""Clear the filter query."""
return {} if n_clicks else no_update
@callback(Output("clear", 'disabled'),
Input("datatable", 'filterModel'),
prevent_initial_call=True)
def enable_clear_filter(filter_query):
"""Enable/disable the clear filter button."""
return filter_query == {}
if __name__ == '__main__':
app.run_server(port=8850, debug=True, threaded=False, use_reloader=False)