Class: AutoColumnSize

AutoColumnSize

handsontable/src/plugins/autoColumnSize/autoColumnSize.js, line 63

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
...
var hot = new Handsontable(document.getElementById('example'), {
  date: getData(),
  autoColumnSize: true
});
// Access to plugin instance:
var plugin = hot.getPlugin('autoColumnSize');

plugin.getColumnWidth(4);

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

Members

firstCalculationBoolean

true only if the first calculation was performed

ghostTableGhostTable

Instance of GhostTable for rows and columns size calculations.

inProgressBoolean

true if the size calculation is in progress.

samplesGeneratorSamplesGenerator

Instance of SamplesGenerator for generating samples necessary for columns width calculations.

widthsArray

Cached columns widths.

Methods

handsontable/src/plugins/autoColumnSize/autoColumnSize.js, line 204

calculateAllColumnsWidth(rowRange)

Calculate all columns width.

Parameters:
Name Type Description
rowRange Object | Number

Row range object.

handsontable/src/plugins/autoColumnSize/autoColumnSize.js, line 177

calculateColumnsWidth(colRange, rowRange, force)

Calculate a columns width.

Parameters:
Name Type Default Description
colRange Number | Object

Column range object.

rowRange Number | Object

Row range object.

force Boolean false optional

If true force calculate width even when value was cached earlier.

handsontable/src/plugins/autoColumnSize/autoColumnSize.js, line 398

clearCache(columns)

Clear 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 Default Description
columns Array [] optional

List of column indexes (physical indexes) to clear.

handsontable/src/plugins/autoColumnSize/autoColumnSize.js, line 496

destroy()

Destroy plugin instance.

handsontable/src/plugins/autoColumnSize/autoColumnSize.js, line 166

disablePlugin()

Disable plugin for this Handsontable instance.

handsontable/src/plugins/autoColumnSize/autoColumnSize.js, line 131

enablePlugin()

Enable plugin for this Handsontable instance.

handsontable/src/plugins/autoColumnSize/autoColumnSize.js, line 370

findColumnsWhereHeaderWasChanged(){Array}

Collects all columns which titles has been changed in comparison to the previous state.

Returns: {Array} It returns an array of physical column indexes.
handsontable/src/plugins/autoColumnSize/autoColumnSize.js, line 315

getColumnWidth(col, defaultWidth, keepMinimum){Number}

Get the calculated column width.

Parameters:
Name Type Default Description
col 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}
handsontable/src/plugins/autoColumnSize/autoColumnSize.js, line 334

getFirstVisibleColumn(){Number}

Get the first visible column.

Returns: {Number} Returns column index or -1 if table is not rendered.
handsontable/src/plugins/autoColumnSize/autoColumnSize.js, line 352

getLastVisibleColumn(){Number}

Get the last visible column.

Returns: {Number} Returns column index or -1 if table is not rendered.
handsontable/src/plugins/autoColumnSize/autoColumnSize.js, line 289

getSyncCalculationLimit(){Number}

Get value which tells how many columns should be calculated synchronously. Rest of the columns will be calculated asynchronously.

Returns: {Number}
handsontable/src/plugins/autoColumnSize/autoColumnSize.js, line 124

isEnabled(){Boolean}

Check if the plugin is enabled in the handsontable settings.

Returns: {Boolean}
handsontable/src/plugins/autoColumnSize/autoColumnSize.js, line 411

isNeedRecalculate(){Boolean}

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

Returns: {Boolean}
handsontable/src/plugins/autoColumnSize/autoColumnSize.js, line 277

recalculateAllColumnsWidth()

Recalculate all columns width (overwrite cache values).

handsontable/src/plugins/autoColumnSize/autoColumnSize.js, line 154

updatePlugin()

Update plugin state.