{hero}

columns().widths()

Since: DataTables 2.0

Get the widths of a group of columns.

Description

This method matches the singular column().width() method in that it gets the widths of columns, but in this case operates over multiple columns and will return an array of values for the selected columns. If you need an overall width, you can then use reduce() to sum them.

As with column().width() it is important to note that the result given is the "outer width" of the cells for the target columns.

The returned numbers might not be an integer, depending on the browser's table rendering.

Type

function columns().widths()

Description:

Compute the widths of the selected columns.

Returns:

The widths of the columns in pixels.

Examples

Get the width of a group of columns:

let table = new DataTable('#example');

let widths = table.columns([0, 1, 2]).widths();

Get the width of all columns:

let table = new DataTable('#example');

let width = table
	.columns()
	.widths()
	.reduce(function (accum, val) {
		return accum + val;
	}, 0);

Related

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