Skip to content

AutoColumnSize

Description

Initializes the plugin, registers the column widths map, and sets up the column resize hook.

Options

autoColumnSize

Source code

autoColumnSize.autoColumnSize : object | boolean

The autoColumnSize option configures the AutoColumnSize plugin.

You can set the autoColumnSize option to one of the following:

SettingDescription
falseDisable the AutoColumnSize plugin
trueEnable the AutoColumnSize plugin with the default configuration
An objectEnable the AutoColumnSize plugin and modify the plugin options

If you set the autoColumnSize option to an object, you can set the following AutoColumnSize plugin options:

PropertyPossible valuesDescription
syncLimitA number | A percentage stringThe number/percentage of columns to keep in sync
(default: 50)
useHeaderstrue | falseWhen calculating column widths:
true: use column headers
false: don’t use column headers
samplingRatioA numberThe number of samples of the same length to be used in column width calculations
allowSampleDuplicatestrue | falseWhen calculating column widths:
true: Allow duplicate samples
false: Don’t allow duplicate samples

By default, the autoColumnSize option is set to undefined, but the AutoColumnSize plugin acts as enabled. To disable the AutoColumnSize plugin completely, set the autoColumnSize option to false.

Using the colWidths option forcibly disables the AutoColumnSize plugin.

Read more:

This option can only be set at the grid level. It has no effect when set in the columns, cells, or cell options.

Default: undefined
Example

autoColumnSize: {
// keep 40% of columns in sync (the rest of columns: async)
syncLimit: '40%',
// when calculating column widths, use column headers
useHeaders: true,
// when calculating column widths, use 10 samples of the same length
samplingRatio: 10,
// when calculating column widths, allow duplicate samples
allowSampleDuplicates: true
},

Members

CALCULATION_CELLS_BUDGET

Source code

AutoColumnSize.CALCULATION_CELLS_BUDGET

Returns the maximum number of cells sampled in a single asynchronous calculation step. Together with CALCULATION_STEP it bounds the work done per animation frame: a column whose row range exceeds the budget is swept across multiple frames, and its width is written once, when the sweep completes.

CALCULATION_STEP

Source code

AutoColumnSize.CALCULATION_STEP

Returns the number of columns processed in a single calculation step during asynchronous sizing.

DEFAULT_SETTINGS

Source code

AutoColumnSize.DEFAULT_SETTINGS

Returns the default settings applied when the plugin is enabled without explicit configuration.

inProgress

Source code

autoColumnSize.inProgress : boolean

true if the size calculation is in progress.

measuredColumns

Source code

autoColumnSize.measuredColumns : number

Number of already measured columns (we already know their sizes).

PLUGIN_KEY

Source code

AutoColumnSize.PLUGIN_KEY

Returns the plugin key used to identify this plugin in Handsontable settings.

PLUGIN_PRIORITY

Source code

AutoColumnSize.PLUGIN_PRIORITY

Returns the priority order used to determine the order in which plugins are initialized.

SETTING_KEYS

Source code

AutoColumnSize.SETTING_KEYS

Returns true so the plugin updates on every updateSettings call, regardless of config object contents.

SYNC_CALCULATION_LIMIT

Source code

AutoColumnSize.SYNC_CALCULATION_LIMIT

Returns the maximum number of columns whose widths are calculated synchronously before switching to async mode.

Methods

calculateAllColumnsWidth

Source code

autoColumnSize.calculateAllColumnsWidth(rowRange, [overwriteCache])

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

ParamTypeDefaultDescription
rowRangeobject
number
Row index or an object with from and to properties which define row range.
[overwriteCache]booleanfalseoptional If true the calculation will be processed regardless of whether the width exists in the cache.

calculateColumnsWidth

Source code

autoColumnSize.calculateColumnsWidth(colRange, rowRange, [overwriteCache])

Calculates a columns width.

ParamTypeDefaultDescription
colRangenumber
object
Visual column index or an object with from and to visual indexes as a range.
rowRangenumber
object
Visual row index or an object with from and to visual indexes as a range.
[overwriteCache]booleanfalseoptional If true the calculation will be processed regardless of whether the width exists in the cache.

calculateVisibleColumnsWidth

Source code

autoColumnSize.calculateVisibleColumnsWidth()

Calculates widths for visible columns in the viewport only.

clearCache

Source code

autoColumnSize.clearCache([physicalColumns])

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.

ParamTypeDescription
[physicalColumns]Array<number>optional List of physical column indexes to clear.

destroy

Source code

autoColumnSize.destroy()

Destroys the plugin instance.

disablePlugin

Source code

autoColumnSize.disablePlugin()

Disables the plugin functionality for this Handsontable instance.

enablePlugin

Source code

autoColumnSize.enablePlugin()

Enables the plugin functionality for this Handsontable instance.

getColumnWidth

Source code

autoColumnSize.getColumnWidth(column, [defaultWidth], [keepMinimum]) ⇒ number

Gets the calculated column width.

ParamTypeDefaultDescription
columnnumberVisual column index.
[defaultWidth]numberoptional Default column width. It will be picked up if no calculated width found.
[keepMinimum]booleantrueoptional If true then returned value won’t be smaller then 50 (default column width).

getFirstVisibleColumn

Source code

autoColumnSize.getFirstVisibleColumn() ⇒ number

Gets the first visible column.

When the MergeCells plugin is enabled with its default virtualized: false setting, a merged cell that crosses the viewport edge extends the rendered column range. In that case this method can return a column index outside the strictly visible viewport. To read the actual visible viewport, use Core#getFirstFullyVisibleColumn or Core#getFirstPartiallyVisibleColumn.

Returns: number - Returns visual column index, -1 if table is not rendered or if there are no columns to base the the calculations on.

getLastVisibleColumn

Source code

autoColumnSize.getLastVisibleColumn() ⇒ number

Gets the last visible column.

When the MergeCells plugin is enabled with its default virtualized: false setting, a merged cell that crosses the viewport edge extends the rendered column range. In that case this method can return a column index outside the strictly visible viewport. To read the actual visible viewport, use Core#getLastFullyVisibleColumn or Core#getLastPartiallyVisibleColumn.

Returns: number - Returns visual column index or -1 if table is not rendered.

getSyncCalculationLimit

Source code

autoColumnSize.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).

isEnabled

Source code

autoColumnSize.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 then the #enablePlugin method is called.

isNeedRecalculate

Source code

autoColumnSize.isNeedRecalculate() ⇒ boolean

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

recalculateAllColumnsWidth

Source code

autoColumnSize.recalculateAllColumnsWidth()

Recalculates all columns width (overwrite cache values).

updatePlugin

Source code

autoColumnSize.updatePlugin()

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