Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Page selection disappears when number of pages decreases to one #892

Closed
mhnrchs opened this issue Apr 20, 2021 · 0 comments · Fixed by #907
Closed

Page selection disappears when number of pages decreases to one #892

mhnrchs opened this issue Apr 20, 2021 · 0 comments · Fixed by #907

Comments

@mhnrchs
Copy link

mhnrchs commented Apr 20, 2021

dash-table version: 4.11.3
Browsers tested: Chromium 78.0.3904.70, Edge 83.0.478.58

On tables where the number of entries (and in consqeuence the number of pages) may change dynamically, dash-table will remain on the currently selected page. If I am on page 4/8 and the number of pages reduces to 2, I will then be on page 4/2.

When this happens, I can use the page selectors to navigate back to previous pages. However, when the number of pages decreases to 1, I am stuck on another page without any apparent way to navigate to the actual content.

Here is a simple example illustrating the issue:
pagechange

And here is the code used to produce the example above:

import dash
import dash_table
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output

app = dash.Dash(__name__)

app.layout = html.Div([
    dcc.Input(
        id='input', type='number',
    ),
    dash_table.DataTable(
        id='table', page_size= 10,
        columns=[{'name':'i', 'id':'i'}, {'name':'square', 'id':'square'}],
    )
])

@app.callback(Output('table', 'data'),
                    Input('input', 'value'))
def update_table_data(val):
    if not val: val = 9
    return [{'i':i, 'square':i**2} for i in range(val+1)]

if __name__ == '__main__':
    app.run_server(debug=True)

This is especially bothersome if the number of table entries cannot be controlled by the user, because the user is then stuck on the non-existing page.

Possible solutions:

  • Automatically change pages when the currently selected page exceeds the new total number of pages: User is on page 4/8, number of pages reduces to 3 -> User is on page 3/3 or 1/3.
  • Do not hide the page selectors if the user is on another page than page 1, even when there is only 1 page in total. This would allow the user to navigate back to the content even in that case.

I am currently handling this by checking myself and updating page_current as needed, but a solution on the side of Dash would be preferred, as I don't think the current behaviour is intended.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
@mhnrchs and others