plotly / dash-table

OBSOLETE: now part of https://github.com/plotly/dash
https://dash.plotly.com
MIT License
420 stars 74 forks source link

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

Closed mhnrchs closed 3 years ago

mhnrchs commented 3 years ago

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:

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.