我想在重置过滤器时有一个初始数据表。
这是初始状态。
如果我应用过滤器,它会给我这样的:
但是在那之后,如果我删除(或重置)过滤器,它不会给我任何东西:
这是我的代码。我认为给出整个代码并不是很有用,因为它有点长。
@app.callback(
Output('update-rowdata-grid', 'rowData'),
Input({'type': 'filter_cat',"table":ALL ,'index': ALL}, 'value'),
# Input({'type': 'filter_num', 'index': MATCH}, 'value'),
# Input({'type': 'filter_date', 'index': MATCH}, 'value')
State('filter_table', 'value'),
State('second_filter','value'),
)
def apply_filter(cat,selected_table,selected_columns):
df = get_selected_dataframe(selected_table)
dff = df.copy()
column_type = df[selected_columns].dtype
if column_type == 'object' and cat:
dff = dff[dff[selected_columns].isin(cat[0])]
else:
return df.to_dict('records')
return dff.to_dict('records')
我认为我们可以使用一些 If-elif 技巧,但我不知道从哪里开始。
你能帮我吗?
鉴于以下问题的背景,我怀疑同样的问题:基于
second_filter
的额外条件。一旦删除,它至少可以在类别上工作。
@app.callback(
Output('update-rowdata-grid', 'rowData', allow_duplicate=True),
Input({'type': 'filter_cat', "table": ALL, 'index': ALL}, 'value'),
State({'type': 'filter_cat', "table": ALL, 'index': ALL}, 'id'),
State('filter_table', 'value'),
prevent_initial_call=True)
def apply_filter(cat, filter_ids, selected_table):
dff = get_selected_dataframe(selected_table).copy()
for filter_id, filter_value in zip(filter_ids, cat):
if filter_value:
dff = dff[dff[filter_id['index']].isin(filter_value)]
return dff.to_dict('records')