LImit the row data displayed in dash table


I had limit the row data displayed in the table.
But how can those row data over the limit able to hide and show an message?

app.layout = dash_table.DataTable(
    columns=[{'id': c, 'name': c} for c in df.columns],

example, based on the above code, the table will only show 10 row data per page, if let say, I had 100 row data in my dataframe, can the other 90 rows data not display in the continue page and show an error like “please provide the specified in the searching criteria.” , so I can control the user to provide specified criteria when they searching to reduce the overloading.

Hello @beginof,

Instead of limiting the page_size, what you can do is limit the df to be the first 10 responses:

Something like this:

app.layout = dash_table.DataTable(
    columns=[{'id': c, 'name': c} for c in df.columns],

Then, as you adjust your search criteria, you just return the updated df with only the top 10 matches.

Thanks @jinnyzor.

If I want top up the feature, can I show a message may be using dbc.Alert or html.div if the table row is over 10?

Yeah. Just have the df trigger an alert if the len(df) > 10. Else don’t show. :grin:

Can you assist to look into the code?
I not sure is it I am scripting correct.

                                [html.H4('🤦🏻‍♂️ Ooops... it is over!'),                                  
                              id= 'alert', 
                              is_open= False,


    Output('alert', 'is_open'), 
    Input('table', 'value')

def display_content(rows):
    if len(rows) > 10:
        return True

    return False

You should be using data instead of value. :slight_smile:

I think that it should work.

Thanks @jinnyzor ,

Can I set the alert to be shown is based on the original table (or the dataframe), means before the data=df[0:10].to_dict('records').

As if after the data=df[0:10].to_dict('records'), mean the table will only show 10 row, and the alert will not appear.

Yes, is actually being the callback info where you are updating the table, that way you don’t have to worry about this issue.

can you share the sample code :grinning:?

Sure. Something like this:

def filterData(v):
dff = df[df[filter == v]]
return dff[0:10].to_dict(‘records’), len(dff) > 10

Where filter is the column you are filtering by and my filter is a drop-down.

1 Like

Thanks @jinnyzor :star_struck:

1 Like