-
-
Notifications
You must be signed in to change notification settings - Fork 73
Table does not default to page 1 after filtering #635
Comments
I'm having exactly the same problem. Any workaround so far? |
Closest thing I've got is to set a callback on page_current so that it resets to 0 every time a filter is applied.
|
Thanks, this works !!! |
Hi, Here is a minimun code reporducing the issue (using import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_table
from dash.dependencies import Input, Output
def _data_with_x_rows(nb_rows):
return [{'value': val} for val in range(0, nb_rows)]
app = dash.Dash()
app.layout = html.Div([
dcc.Input(
id="nb-table-entries",
type="number",
value=20,
),
dash_table.DataTable(
id='datatable',
columns=[{'name': 'value', 'id': 'value'}],
page_size=5,
data=_data_with_x_rows(20)
),
])
@app.callback(Output('datatable', 'data'),
[Input('nb-table-entries', 'value')])
def _update_table_data(value):
return _data_with_x_rows(int(value if value else 0))
if __name__ == '__main__':
app.run_server(debug=True) FYI, I found another workaround by simply updating all the table component instead of only the |
Hi slemouzy, I have same issue. Could you please share how to update the table component? Thanks |
Sorry @wang-zifu for the time I took for my answer, here is an example of the workaround I used: import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_table
from dash.dependencies import Input, Output
def _data_with_x_rows(nb_rows):
return [{'value': val} for val in range(0, nb_rows)]
app = dash.Dash()
app.layout = html.Div([
dcc.Input(
id="nb-table-entries",
type="number",
value=20,
),
html.Div(id='table-div', children=_table_with_data(value))
])
@app.callback(Output('table-div', 'children'),
[Input('nb-table-entries', 'value')])
def _table_with_data(value):
return dash_table.DataTable(
id='datatable',
columns=[{'name': 'value', 'id': 'value'}],
page_size=5,
data=_data_with_x_rows(int(value if value else 0))
)
if __name__ == '__main__':
app.run_server(debug=True) I actually don't have the time to test this small peace of code, but I hope you will have the principle of the workaround. |
After filtering a column in the table, page number is not reset to 1. This causes no problem when filtering is applied whilst page 1 is being inspected, but when looking at a higher page, if the filter applied reduces the size of the table to below the current page number, the forward and previous buttons are removed and navigation becomes impossible.
The buttons return upon removal of the filter, but it can be bothersome to have to return to page 1 before applying any filters.
The text was updated successfully, but these errors were encountered: