This plugin allows to set row heights based on their highest cells.
By default, the plugin is declared as undefined
, which makes it disabled (same as if it was declared as false
).
Enabling this plugin may decrease the overall table performance, as it needs to calculate the heights of all cells to
resize the rows accordingly.
If you experience problems with the performance, try turning this feature off and declaring the row heights manually.
Row height 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)
autoRowSize: {syncLimit: 300},
// as a string (percent)
autoRowSize: {syncLimit: '40%'},
// allow sample duplication
autoRowSize: {syncLimit: '40%', allowSampleDuplicates: true},
You can also use the allowSampleDuplicates
option to allow sampling duplicate values when calculating the row
height. Note, that this might have a negative impact on performance.
To configure this plugin see Options#autoRowSize
.
Example
const hot = new Handsontable(document.getElementById('example'), {
date: getData(),
autoRowSize: true
});
// Access to plugin instance:
const plugin = hot.getPlugin('autoRowSize');
plugin.getRowHeight(4);
if (plugin.isEnabled()) {
// code...
}
Members
-
heightsArray.<Number>
-
Cached rows heights.
-
inProgressBoolean
-
true
if the size calculation is in progress.
Methods
-
calculateAllRowsHeight(rowRange)
-
Calculate all rows heights. The calculated row will be cached in the
AutoRowSize#heights
property.
To retrieve height for specyfied row useAutoRowSize#getRowHeight
method.Parameters:
Name Type Description rowRange
Object | Number Row index or an object with
from
andto
properties which define row range. -
calculateRowsHeight(rowRange, colRange, force)
-
Calculate a given rows height.
Parameters:
Name Type Default Description rowRange
Number | Object Row index or an object with
from
andto
indexes as a range.colRange
Number | Object Column index or an object with
from
andto
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()
-
Clears cached heights.
-
clearCacheByRange(range)
-
Clears cache by range.
Parameters:
Name Type Description range
Object | Number Row index or an object with
from
andto
properties which define row range. -
destroy()
-
Destroys the plugin instance.
-
disablePlugin()
-
Disables the plugin functionality for this Handsontable instance.
-
enablePlugin()
-
Enables the plugin functionality for this Handsontable instance.
-
getColumnHeaderHeight(){Number|undefined}
-
Get the calculated column header height.
Returns: {Number|undefined}
-
getFirstVisibleRow(){Number|null}
-
Get the first visible row.
Returns: {Number|null} Returns row index, -1 if table is not rendered or null if there are no rows to base the the calculations on.
-
getLastVisibleRow(){Number}
-
Gets the last visible row.
Returns: {Number} Returns row index or -1 if table is not rendered.
-
getRowHeight(row, defaultHeight){Number}
-
Gets the calculated row height.
Parameters:
Name Type Description row
Number Visual row index.
defaultHeight
Number optional Default row height. It will be picked up if no calculated height found.
Returns: {Number}
-
getSyncCalculationLimit(){Number}
-
Gets value which tells how many rows should be calculated synchronously (rest of the rows will be calculated
asynchronously). The limit is calculated based onsyncLimit
set to autoRowSize option (seeOptions#autoRowSize
).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 returnstrue
than theAutoRowSize#enablePlugin
method is called.Returns: {Boolean}
-
isNeedRecalculate(){Boolean}
-
Checks if all heights were calculated. If not then return
true
(need recalculate).Returns: {Boolean}
-
recalculateAllRowsHeight()
-
Recalculates all rows height (overwrite cache values).