I have 4 columns in my data of which col 1 and 2 are small, and the col 3 and 4 are long. With automatic widths, I find the col 3 and 4 are too long and I want to use an ellipsis and a tooltip to make the last two columns compact.
So I decided to use style_cell_conditional to override the width and specify my own column sizes. But I can’t get that to work along with the ellipsis.
From the docs, I understand that maxWidth is necessary to display the ellipsis but why are the smaller columns which don’t need any ellipsis increasing in width?
dash_table.DataTable(
columns=[{"name": i, "id": i} for i in yt_df.columns],
data=yt_df.to_dict('records'),
style_header={'backgroundColor': 'rgb(30, 30, 30)', 'color': 'white'},
column_selectable="single",
style_data={
'minWidth': '96px', 'width': '150px', 'maxWidth': '200px',
},
style_cell_conditional=[
{'if':{'column_id': 'video_id'},
'width': '96px'},
{'if':{'column_id': 'publishedDate'},
'width': '144px'},
{'if':{'column_id': 'title'},
'width': '200px'},
{'if':{'column_id': 'comments'},
'width': '200px'}
],
style_cell={'textAlign': 'left',
'padding': '5px',
'overflow': 'hidden',
'textOverflow': 'ellipsis',
# 'maxWidth': 0
},
tooltip_data=[
{
column: {'value': str(value), 'type': 'markdown'}
for column, value in row.items()
} for row in yt_df.to_dict('records')
],
tooltip_duration=None,
style_table={'height': '330px', 'width': '100%', 'overflowY': 'auto'}, # Scroll
fixed_rows={'headers': True},
page_size= 10
)
Tldr:
How the code is behaving :
- All columns of the same width with ellipsis
or - All columns fit to the width of the data, with horizontal scroll but without ellipsis
What I want to know :
- Smaller columns with smaller width, longer columns with a fixed width and ellipsis
- I don’t see any difference in changing any of these values
'minWidth': '96px', 'width': '150px', 'maxWidth': '200px',
, what exactly do these do? - Why isn’t the
style_cell_conditional
overriding the column widths?
I’ve tried my best to explain this as clearly as possible. Please do let me know if anything is unclear. Thanks in advance!