AutoRowHeaderSize
Options
autoRowHeaderSize
Can be set at: grid
autoRowHeaderSize.autoRowHeaderSize : object | boolean
The autoRowHeaderSize option configures the AutoRowHeaderSize plugin.
The plugin sizes the row header column to its widest label, the way
AutoColumnSize sizes a data column to its widest cell. Turning it
on is all you need: it takes the row header’s width over, so any
rowHeaderWidth already set is ignored while the plugin is enabled.
You can set the autoRowHeaderSize option to one of the following:
| Setting | Description |
|---|---|
false | Disable the AutoRowHeaderSize plugin |
true | Enable the plugin with the default configuration |
| An object | Enable the plugin and modify its options |
If you set the autoRowHeaderSize option to an object, you can set the following options:
| Property | Possible values | Description |
|---|---|---|
samplingRatio | A number | The number of samples of the same label length used in the measurement (default: 3) |
allowSampleDuplicates | true | false | When two rows carry the same label:true: measure bothfalse: measure it once(default: false) |
syncLimit | A number | a percent string | How many rows are read before the first paint; the rest are read in idle time (default: 500) |
By default, the autoRowHeaderSize option is set to undefined, which disables the plugin.
Finding the longest label means reading every row header once. On a large grid that work is
split: the first syncLimit rows are read before the first paint, and the rest are read in
the browser’s idle time, so a header can widen a moment after the grid appears. While that is
running a header only ever widens, so its width never jumps back and forth. The result is
cached, so later draws cost nothing.
Editing a cell does not re-read the whole grid. Only the rows that changed are read, because
a row header label can be built from cell values, and that reading waits for an idle moment
too. It can make a header wider, but never narrower: a header shrinks again on the next full
pass, which is started by loading or replacing the data, adding or removing a row, sorting,
hiding or showing a row, switching the theme, or a recalculation by the
Formulas plugin.
A grid can render more than one row header, by pushing a renderer through the
afterGetRowHeaderRenderers hook. Every one of
them is measured on its own, so each gets exactly the width its own labels need.
The measured width leaves a little room around the longest label, so the text never sits flush
against the cell border. The grid’s own row header renderer wraps its label in a padded
element, but a renderer pushed through
afterGetRowHeaderRenderers writes straight into
the cell and has none of its own.
Two rows carrying the same label are measured once, since the same text renders to the same
width. Set allowSampleDuplicates to true when that is not true of your grid - a row header
that is indented per row, as nestedRows does, renders the same label at a
different width depending on its depth. Raise samplingRatio along with it: labels are
grouped by length and only samplingRatio of each group are measured, so with the default of
3 a fourth copy of the same label is still left out, however deep it sits.
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
Since: 19.0.0
Example
// size the row header column to its longest labelautoRowHeaderSize: true,
// the same, with the measurement tunedautoRowHeaderSize: { // measure repeated labels too, for headers that render differently per row allowSampleDuplicates: true,},Members
CALCULATION_BUDGET
AutoRowHeaderSize.CALCULATION_BUDGET ⇒ number
Returns how long one idle chunk may spend reading labels, in milliseconds.
A row count alone would be either wasteful or unsafe: reading a label costs well under a
microsecond for the first header level and several times that for each level added through the
hook, so the same number of rows is a rounding error in one grid and a dropped frame in
another. Going by time keeps a chunk inside a frame either way, which matters because
requestIdleCallback is missing on some supported browsers - there the chunk runs in an
animation frame instead.
CALCULATION_STEP
AutoRowHeaderSize.CALCULATION_STEP ⇒ number
Returns the number of rows read between two checks of the chunk’s time budget.
DEFAULT_SETTINGS
AutoRowHeaderSize.DEFAULT_SETTINGS
Returns the default settings applied when the plugin is enabled without explicit configuration.
null means “leave it to the sampler”, matching how the sibling auto-size plugins express the
same idea. Only settings this plugin actually reads are declared here.
MEASUREMENT_PADDING
AutoRowHeaderSize.MEASUREMENT_PADDING ⇒ number
Returns the breathing space added to every measured level, in pixels.
The ghost table measures the cell exactly as it renders, which is a problem when a row header
renderer writes its text straight into the th: the grid’s own renderer wraps the label in a
padded element, but a renderer pushed through the hook has no padding at all, so an exact
measurement leaves the longest label flush against the cell border. Rather than require every
renderer to style itself, the width carries a small allowance.
PLUGIN_KEY
AutoRowHeaderSize.PLUGIN_KEY ⇒ string
The plugin’s setting key.
PLUGIN_PRIORITY
AutoRowHeaderSize.PLUGIN_PRIORITY ⇒ number
The plugin’s initialization priority.
SETTING_KEYS
AutoRowHeaderSize.SETTING_KEYS
Returns true so the plugin updates on every updateSettings call, regardless of config object contents.
SYNC_CALCULATION_LIMIT
AutoRowHeaderSize.SYNC_CALCULATION_LIMIT ⇒ number
Returns the number of rows read before the first paint, when syncLimit says nothing else.
Every existing unit test runs on fewer rows than this, so they measure synchronously and never have to drive the idle sweep.
Methods
clearCache
autoRowHeaderSize.clearCache()
Throws the measured widths away, so the next read measures again.
destroy
autoRowHeaderSize.destroy()
Destroys the plugin instance.
disablePlugin
autoRowHeaderSize.disablePlugin()
Disables the plugin functionality for this Handsontable instance.
enablePlugin
autoRowHeaderSize.enablePlugin()
Enables the plugin functionality for this Handsontable instance.
getRowHeaderWidth
autoRowHeaderSize.getRowHeaderWidth([headerLevel]) ⇒ number
Returns the width one row header level needs in order to show its longest label in full.
On a grid larger than syncLimit this can still be growing - the rows past that limit are read
in the browser’s idle time, so a level can report a wider figure a moment later.
| Param | Type | Default | Description |
|---|---|---|---|
| [headerLevel] | number | 0 | optional Which row header to report on, counting from the grid’s edge: 0 is the first one. The negative column index a row header sits at is accepted too, so -1 is that same first header and -2 the one after it. |
Returns: number - The measured width in pixels, or 0 when there is nothing to measure.
getRowHeaderWidths
autoRowHeaderSize.getRowHeaderWidths() ⇒ Array<number>
Returns the width every row header level needs, in order, starting with the one at the grid’s edge.
Returns: Array<number> - The measured widths in pixels.
getSyncCalculationLimit
autoRowHeaderSize.getSyncCalculationLimit() ⇒ number
Returns how many rows are read before the first paint.
A plain number is taken as it is, and a percent string is resolved against the row count, the
way AutoColumnSize resolves its own. Anything else keeps the default, so an object
config that only sets samplingRatio still gets a measured first paint.
isEnabled
autoRowHeaderSize.isEnabled() ⇒ boolean
Checks if the plugin is enabled in the handsontable settings.
updatePlugin
autoRowHeaderSize.updatePlugin([newSettings])
Updates the plugin’s state.
| Param | Type | Description |
|---|---|---|
| [newSettings] | object | optional The settings passed to updateSettings. |