Class: AutoColumnSize

AutoColumnSize

This plugin allows to set column widths based on their widest cells.

By default, the plugin is declared as undefined, which makes it enabled (same as if it was declared as true).
Enabling this plugin may decrease the overall table performance, as it needs to calculate the widths of all cells to
resize the columns accordingly.
If you experience problems with the performance, try turning this feature off and declaring the column widths manually.

Column width calculations are divided into sync and async part. Each of this parts has their own advantages and
disadvantages. Synchronous calculations are faster but they block the browser UI, while the slower asynchronous
operations don't block the browser UI.

To configure the sync/async distribution, you can pass an absolute value (number of columns) or a percentage value to a config object:

// as a number (300 columns in sync, rest async)
autoColumnSize: {syncLimit: 300},

// as a string (percent)
autoColumnSize: {syncLimit: '40%'},

To configure this plugin see Options#autoColumnSize.

Example
const hot = new Handsontable(document.getElementById('example'), {
  date: getData(),
  autoColumnSize: true
});
// Access to plugin instance:
const plugin = hot.getPlugin('autoColumnSize');

plugin.getColumnWidth(4);

if (plugin.isEnabled()) {
  // code...
}

Members

inProgressBoolean

true if the size calculation is in progress.

widthsArray.<Number>

Cached columns widths.

Methods

calculateAllColumnsWidth(rowRange)

Calculates all columns width. The calculated column will be cached in the AutoColumnSize#widths property.
To retrieve width for specyfied column use AutoColumnSize#getColumnWidth method.

Parameters:
Name Type Description
rowRange Object | Number

Row index or an object with from and to properties which define row range.

calculateColumnsWidth(colRange, rowRange, force)

Calculates a columns width.

Parameters:
Name Type Default Description
colRange Number | Object

Column index or an object with from and to indexes as a range.

rowRange Number | Object

Row index or an object with from and to indexes as a range.

force Boolean false optional

If true the calculation will be processed regardless of whether the width exists in the cache.

clearCache(columns)

Clears cache of calculated column widths. If you want to clear only selected columns pass an array with their indexes.
Otherwise whole cache will be cleared.

Parameters:
Name Type Description
columns Array.<Number> optional

List of physical column indexes to clear.

destroy()

Destroys the plugin instance.

disablePlugin()

Disables the plugin functionality for this Handsontable instance.

enablePlugin()

Enables the plugin functionality for this Handsontable instance.

getColumnWidth(column, defaultWidth, keepMinimum){Number}

Gets the calculated column width.

Parameters:
Name Type Default Description
column Number

Column index.

defaultWidth Number optional

Default column width. It will be picked up if no calculated width found.

keepMinimum Boolean true optional

If true then returned value won't be smaller then 50 (default column width).

Returns: {Number}

getFirstVisibleColumn(){Number}

Gets the first visible column.

Returns: {Number} Returns column index or -1 if table is not rendered.

getLastVisibleColumn(){Number}

Gets the last visible column.

Returns: {Number} Returns column index or -1 if table is not rendered.

getSyncCalculationLimit(){Number}

Gets value which tells how many columns should be calculated synchronously (rest of the columns will be calculated
asynchronously). The limit is calculated based on syncLimit set to autoColumnSize option (see Options#autoColumnSize).

Returns: {Number}

isEnabled(){Boolean}

Checks if the plugin is enabled in the handsontable settings. This method is executed in Hooks#beforeInit
hook and if it returns true than the AutoColumnSize#enablePlugin method is called.

Returns: {Boolean}

isNeedRecalculate(){Boolean}

Checks if all widths were calculated. If not then return true (need recalculate).

Returns: {Boolean}

recalculateAllColumnsWidth()

Recalculates all columns width (overwrite cache values).

updatePlugin()

Updates the plugin state. This method is executed when Core#updateSettings is invoked.