plotly / dash-table-experiments

NO LONGER SUPPORTED - use https://github.com/plotly/dash-table instead
MIT License
174 stars 55 forks source link

Assigning new rows didn't reset selected indices if callback exist #22

Open EvgeniiAl opened 6 years ago

EvgeniiAl commented 6 years ago

Hello, there are two datables with and without callback in provided example.

  1. Checkbox "1" is set by default
  2. Check "select all" in both datatables
  3. Check/uncheck "0" checkbox to see difference
    
    # -*- coding: utf-8 -*-
    import dash
    import dash_core_components as dcc
    import dash_html_components as html
    from dash.dependencies import Input, Output
    import dash_table_experiments as dte
    import pandas as pd
    import numpy as np

MAGIC_NUM = 5 dfs = [] for x in range(MAGIC_NUM): df = pd.DataFrame(np.random.randn(5, 2), columns=['df', 'value']) df['df'] = x dfs.append(df) dfs = pd.concat(dfs)

app = dash.Dash() app.scripts.config.serve_locally = True app.layout = html.Div([ dcc.Checklist( id='check-df', options=[{'label': x, 'value': x} for x in range(MAGIC_NUM)], values=[1] ), html.Div( id='dummy' ), html.Div([dte.DataTable( id='datatable_1', rows=dfs.to_dict('records'), columns=dfs.columns, row_selectable=True )], style={'width': '49%', 'display': 'inline-block'}), html.Div([dte.DataTable( id='datatable_2', rows=dfs.to_dict('records'), columns=dfs.columns, row_selectable=True )], style={'width': '49%', 'display': 'inline-block'}), ])

@app.callback( Output('datatable_1', 'rows'), [Input('check-df', 'values')]) def change_df(values): return dfs[dfs['df'].isin(values)].to_dict('records')

@app.callback( Output('datatable_2', 'rows'), [Input('check-df', 'values')]) def change_df(values): return dfs[dfs['df'].isin(values)].to_dict('records')

@app.callback( Output('dummy', 'children'), [Input('datatable_1', 'rows'), Input('datatable_1', 'selected_row_indices')]) def on_select(rows, selected_row_indices): return None

if name == 'main': app.run_server()

hawktang commented 6 years ago

Keep the indices might not bad thing, but the problem is that the indices in hide somehow