ipydatagrid
supports auto-fitting of column widths!¶The DataGrid constructor can take the following arguments:
auto_fit_columns
: boolean, indicates whether to auot-fit column widths. Setting to False will reset all column sizes to base_column_size
.auto_fit_params
: dict, allows for more granular customisation of the auto-fitting algorithm:area
: select which section of the grid to apply auto-fitting on. Possible options are all
, row-header
(index column) and body
.padding
: specifies how much padding should be added to the width of each column after resizing (default 30)numCols
: set a hard cap on the number of columns to resize for the selected area (optional). Not setting this value means there is no cap.import numpy as np
import pandas as pd
from ipydatagrid import DataGrid
df = pd.DataFrame(
data={
"Col1HasAVeryLongName": [1, 2, 4],
"Col2MediumName": [4, 5, 6],
"Col3": [7, 8, 9],
}
)
grid = DataGrid(df, index_name="index_column", layout={"height": "90px"})
grid
DataGrid(auto_fit_params={'area': 'all', 'padding': 30, 'numCols': None}, corner_renderer=None, default_render…
grid.auto_fit_columns = True
grid.auto_fit_columns = False
grid.auto_fit_params = {"area": "body", "padding": 60, "numCols": 1}
grid.auto_fit_columns = True