How to selected row by using keyboard press up & down focus cell?
For the cell clicked example, you can select a cell by mouse click,but can’t use keyboard press up & down to focus cell.
But in dash_table.DataTable,you can use keyboard press up & down to callback active cell then get cell informations.
So how to selected row by using keyboard press up & down to focus cell then callback cell information?
from dash import Dash, html, Input, Output, callback
import dash_ag_grid as dag
import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/solar.csv")
app = Dash(__name__)
grid = dag.AgGrid(
id="quickstart-grid",
rowData=df.to_dict("records"),
columnDefs=[{"field": i} for i in df.columns],
defaultColDef={"resizable": True, "sortable": True, "filter": True, "minWidth":125},
columnSize="sizeToFit",
getRowId="params.data.State"
)
app.layout = html.Div([grid, html.Div(id="quickstart-output")])
@callback(
Output("quickstart-output", "children"), Input("quickstart-grid", "cellClicked")
)
def display_cell_clicked_on(cell):
if cell is None:
return "Click on a cell"
return f"clicked on cell value: {cell['value']}, column: {cell['colId']}, row index: {cell['rowIndex']}"
if __name__ == "__main__":
app.run(debug=True)