columns.adjust()

Since: DataTables 1.10

Recalculate the column widths.

Description

Like HTML tables, DataTables attempts to layout tables in an optimal format based on the data in the cells. As the data changes, it can sometimes be useful to recalculate this layout. Additionally DataTables makes extensive use of the dimensions of DOM elements in the table which scrolling is enabled (to align the columns) so if a table is hidden when initialised the height / width of the table elements will be unavailable.

This method is provided to have DataTables recalculate the columns sizes, based on the data in the table and the size applied to the columns (in the DOM, CSS or through the columns.width parameter). Call it when the table becomes visible if hidden when initialised (for example in a tab) or when the data changes significantly.

DataTables will automatically call this method on the window resize event to keep the columns in sync with the re-flowed layout.

Type

function columns.adjust()

Description:

Recalculate the column widths for layout.

Returns:

DataTables API instance.

Example

Adjust the column sizes of a newly shown table:

var table = $('#example').DataTable();

$('#container').css( 'display', 'block' );
table.columns.adjust().draw();

Related

The following options are directly related and may also be useful in your application development.