使用下拉列表过滤数据表

时间:2019-08-28 23:04:14

标签: python pandas hyphen

我在Dash中有一个数据表,我需要让用户使用下拉列表对其进行过滤(基本过滤没有多过滤器,因此我不得不放弃键入操作)。我创建了下拉列表,但我不知道如何编写回调。我在下面粘贴了下拉菜单和数据表的代码,如果有人可以帮助,我们将非常高兴。

    html.Div([
dcc.Dropdown(id='owner', options=[
    {'label': i, 'value': i} for i in df.O_Name.unique()
], multi=True, placeholder='Select owner'),
html.Div(id='owners')],
style={'width': '15%', 'display': 'inline-block'}),

        html.Div([
dcc.Dropdown(id='source', options=[
    {'label': i, 'value': i} for i in df.PZ_Name_Source.unique()
], multi=True, placeholder='Select source'),
html.Div(id='sources')],
style={'width': '15%', 'display': 'inline-block'}),

        html.Div([
dcc.Dropdown(id='destination', options=[
    {'label': i, 'value': i} for i in df.PZ_Name_Destination.unique()
], multi=True, placeholder='Select destination'),
html.Div(id='destinations')],
style={'width': '15%', 'display': 'inline-block'}),

        html.Div([
dcc.Dropdown(id='tariff', options=[
    {'label': i, 'value': i} for i in df.TariffName.unique()
], multi=True, placeholder='Select tariff'),
html.Div(id='tariffs')],
style={'width': '15%', 'display': 'inline-block'}),

        html.Div([
dcc.Dropdown(id='period', options=[
    {'label': i, 'value': i} for i in df.Period.unique()
], multi=True, placeholder='Select period'),
html.Div(id='periods')],
style={'width': '15%', 'display': 'inline-block'}),


    html.A(
    html.Button('Export to CSV'),
    id='download-link',
    download="coeffmap.csv",
    href="",
    target="_blank"
    ),


    html.A(
    html.Button('Export to SQL'),
    id='sql-link',
    #download="coeffmap.csv",
    href="",
    target="_blank"
    ),   


html.Div([dash_table.DataTable(
    id='datatable',
    columns=[
        {"name": i, "id": i, "deletable": True} for i in df.columns
    ],
    data=df.to_dict('rows'),
    #export_format='csv',
    #export_headers='names',
    editable=True,
    filter_action="native",
    sort_action="native",
    sort_mode="multi",
    row_selectable="multi",
    row_deletable=True,
    selected_rows=[],
    page_action="native",

    page_current= 0,
    page_size= 10000,
),
html.Div(id='table')]),
 html.Div(id='datatable-interactivity-container')

0 个答案:

没有答案