Column Definitions

Column Definitions#

The columnDefs.width argument let you adjust the column widths.

Note that the default value of style, or of autoWidth (defaults to True), might override custom column widths, so you might have to change their values as in the examples below.

You can set a fixed width for all the columns with "targets": "_all":

import itables

itables.init_notebook_mode()

df = itables.sample_dfs.get_countries(html=False)

itables.show(
    df,
    columnDefs=[{"width": "120px", "targets": "_all"}],
    style="width:1200px",
    autoWidth=False,
)
Loading ITables v2.4.0rc1 from the init_notebook_mode cell... (need help?)

You can also adjust the width of selected columns only:

itables.show(
    df,
    columnDefs=[{"width": "30%", "targets": [2, 3]}],
    style="width:100%;margin:auto",
)
Loading ITables v2.4.0rc1 from the init_notebook_mode cell... (need help?)

If you wish you can also set a value for columnDefs permanently in itables.options as demonstrated in the cell alignment example below.

You can use the DataTables cell classes like dt-left, dt-center, dt-right etc. to set the cell alignment. Specify it for one table by using the columnDefs argument of show

itables.show(df, columnDefs=[{"className": "dt-center", "targets": "_all"}])
Loading ITables v2.4.0rc1 from the init_notebook_mode cell... (need help?)

or globally by setting itables.options.columnDefs:

itables.options.columnDefs = [{"className": "dt-center", "targets": "_all"}]

df
Loading ITables v2.4.0rc1 from the init_notebook_mode cell... (need help?)