AutoColumnSize
Description
Initializes the plugin, registers the column widths map, and sets up the column resize hook.
Options
autoColumnSize
autoColumnSize.autoColumnSize : object | boolean
The autoColumnSize option configures the AutoColumnSize plugin.
You can set the autoColumnSize option to one of the following:
| Setting | Description |
|---|---|
false | Disable the AutoColumnSize plugin |
true | Enable the AutoColumnSize plugin with the default configuration |
| An object | Enable 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:
| Property | Possible values | Description |
|---|---|---|
syncLimit | A number | A percentage string | The number/percentage of columns to keep in sync (default: 50) |
useHeaders | true | false | When calculating column widths:true: use column headersfalse: don’t use column headers |
samplingRatio | A number | The number of samples of the same length to be used in column width calculations |
allowSampleDuplicates | true | false | When calculating column widths:true: Allow duplicate samplesfalse: 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
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
AutoColumnSize.CALCULATION_STEP
Returns the number of columns processed in a single calculation step during asynchronous sizing.
DEFAULT_SETTINGS
AutoColumnSize.DEFAULT_SETTINGS
Returns the default settings applied when the plugin is enabled without explicit configuration.
inProgress
autoColumnSize.inProgress : boolean
true if the size calculation is in progress.
measuredColumns
autoColumnSize.measuredColumns : number
Number of already measured columns (we already know their sizes).
PLUGIN_KEY
AutoColumnSize.PLUGIN_KEY
Returns the plugin key used to identify this plugin in Handsontable settings.
PLUGIN_PRIORITY
AutoColumnSize.PLUGIN_PRIORITY
Returns the priority order used to determine the order in which plugins are initialized.
SETTING_KEYS
AutoColumnSize.SETTING_KEYS
Returns true so the plugin updates on every updateSettings call, regardless of config object contents.
SYNC_CALCULATION_LIMIT
AutoColumnSize.SYNC_CALCULATION_LIMIT
Returns the maximum number of columns whose widths are calculated synchronously before switching to async mode.
Methods
calculateAllColumnsWidth
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.
| Param | Type | Default | Description |
|---|---|---|---|
| rowRange | object number | Row index or an object with from and to properties which define row range. | |
| [overwriteCache] | boolean | false | optional If true the calculation will be processed regardless of whether the width exists in the cache. |
calculateColumnsWidth
autoColumnSize.calculateColumnsWidth(colRange, rowRange, [overwriteCache])
Calculates a columns width.
| Param | Type | Default | Description |
|---|---|---|---|
| colRange | number object | Visual column index or an object with from and to visual indexes as a range. | |
| rowRange | number object | Visual row index or an object with from and to visual indexes as a range. | |
| [overwriteCache] | boolean | false | optional If true the calculation will be processed regardless of whether the width exists in the cache. |
calculateVisibleColumnsWidth
autoColumnSize.calculateVisibleColumnsWidth()
Calculates widths for visible columns in the viewport only.
clearCache
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.
| Param | Type | Description |
|---|---|---|
| [physicalColumns] | Array<number> | optional List of physical column indexes to clear. |
destroy
autoColumnSize.destroy()
Destroys the plugin instance.
disablePlugin
autoColumnSize.disablePlugin()
Disables the plugin functionality for this Handsontable instance.
enablePlugin
autoColumnSize.enablePlugin()
Enables the plugin functionality for this Handsontable instance.
getColumnWidth
autoColumnSize.getColumnWidth(column, [defaultWidth], [keepMinimum]) ⇒ number
Gets the calculated column width.
| Param | Type | Default | Description |
|---|---|---|---|
| column | number | Visual 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). |
getFirstVisibleColumn
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
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
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
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
autoColumnSize.isNeedRecalculate() ⇒ boolean
Checks if all widths were calculated. If not then return true (need recalculate).
recalculateAllColumnsWidth
autoColumnSize.recalculateAllColumnsWidth()
Recalculates all columns width (overwrite cache values).
updatePlugin
autoColumnSize.updatePlugin()
Updates the plugin’s state. This method is executed when Core#updateSettings is invoked.