Tabulator is a great component.
It’s blistering fast when the height is set to a fix amount (eg ‘500px’).
Because tabulator automatically optimizes memory with a fixed height.
So we’d like to keep the speed.
But the fixed height is a problem in most practical cases.
What we need is a Tabulator that scales along with it’s parent but that stays blistering fast.
Also according to the tabulator js docs, you can ‘manage’ preloading by providing a ‘renderVerticalBuffer’
But it doesn’t seem to work
fixed height of 500px
when rescaling:
When rescaling the window (or any standard html.Div) the table height should rescale automatically (ie. pagination should stay visible)
Like in this badly photoshopped examlpe
So Setting
maxHeight=“100%”,
renderVerticalBuffer=50,
should resolve this, but it doesn’t work…
Probably something trivial for someone who knows what he is doing.
Kinda stuck on this…
import numpy as np
import pandas as pd
import dash
from dash import html, dcc
import dash_tabulator
df = pd.DataFrame(np.random.randint(0,100,size=(1000, 4)), columns=list('ABCD'))
tabulator_columns = [{"title": x,
"field": x,
} for x in df.columns
]
# Set tabulator fix-height via tabulator options to
tabulator_options = dict(
# 1 - Works as expected but impossible to resize dynamically
height="500px",
# 2 - Doesn't work. Same as simple 100%
#maxHeight="100%",
#renderVerticalBuffer=50,
# 3 - Doesn't work.
#height="calc(100%-10px)",
pagination="local",
paginationSize=100,
paginationSizeSelector=[10,50,200,500,True],
frozenRows=1,
)
df['id']=df.index
data = list(df.T.to_dict().values())
tabulator = dash_tabulator.DashTabulator(
id = 'tabulator',
data = data,
columns = tabulator_columns,
options = tabulator_options,
theme = "tabulator",
)
external_scripts = ['https://oss.sheetjs.com/sheetjs/xlsx.full.min.js']
external_stylesheets = ['https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css',
'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css']
app = dash.Dash(__name__, external_scripts=external_scripts, external_stylesheets=external_stylesheets)
app.layout = html.Div([
tabulator
], style={'width':'100%', 'max-height':'100%', 'overflow':'auto'})
if __name__ == '__main__':
app.run_server(debug=True)