Row heights
Configure row heights, using a number, an array or a function. Let your users manually change row heights using Handsontable DataGrid’s interface.
Overview
The default row height is calculated based on the used theme’s line height, vertical padding and cell border values and in the main theme it’s 29px, in the horizon it’s 37px and in the classic styles it’s 26 px. Unless configured otherwise, Handsontable assumes that your cell contents fit in this default row height.
Two options set row heights, and they differ in what happens when the content doesn’t fit:
| Option | Row height | Content taller than the row |
|---|---|---|
rowHeights | Exactly the height you set, even below default | Clipped |
minRowHeights | At least the height you set, never below default | Grows the row to fit |
There is one exception to these heights. In the built-in themes, the first row of the frozen bottom rows is drawn one pixel taller than the height you set, whichever of the two options sets it. That pixel is the freeze line above the row, and the grid doesn’t count it as part of the row’s height.
Both options accept a number, an array, or a function. You can set both: rowHeights sets the rows it gives a height, and minRowHeights applies to the others. When you enable the AutoRowSize plugin, rowHeights is a minimum too, because the plugin lets each row grow to fit its content.
If your cell contents require heights greater than default (because you use multiline text, or custom renderers, or custom styles), and you don’t want them clipped, use one of the following configurations to avoid potential layout problems:
- Configure your row heights in advance: set the
minRowHeightsoption to a number, or an array, or a function. This requires you to know the heights beforehand, but results in the best runtime performance. - Set the
manualRowResizeoption to an array, to configure initial row heights and let your users adjust the row heights manually. - Enable the
AutoRowSizeplugin, by settingautoRowSize: true. This tells Handsontable to measure the actual row heights in the DOM. It impacts runtime performance but is accurate. Also enableAutoRowSizeif you callscrollViewportTo()— the method relies on accurate row height measurements to scroll to the correct position.
To make rows shorter than the default row height, for example to use empty rows as separators, set rowHeights and leave AutoRowSize off. The ManualRowResize plugin doesn’t make a row shorter than the default row height. When it is enabled, a row that a rowHeights height covers stays at the height the user drags it to and clips its content, and a row that rowHeights gives no height grows to fit its content.
Content that doesn’t fit an exact row stays in the DOM and screen readers read it, but it is cut off on the screen. A row doesn’t grow when a user enlarges the text or overrides the text spacing, so leave room for it, or use minRowHeights.
Set row heights to a number
We set the same height of 40px for all rows across the entire grid in this example.
<script setup lang="ts">import { ref } from 'vue';import { HotTable } from '@handsontable/vue3';import { registerAllModules } from 'handsontable/registry';import type { GridSettings } from 'handsontable/settings';
registerAllModules();
const hotSettings = ref<GridSettings>({ data: [ ['SKU-4821', 'Stainless Steel Water Bottle', 'Harbor Goods', 'Drinkware', 'Seattle'], ['SKU-0093', 'Wireless Mouse', 'Alpine Supply Co.', 'Electronics', 'Denver'], ['SKU-1170', 'Ergonomic Office Chair', 'Cascade Distributors', 'Furniture', 'Portland'], ['SKU-2208', 'USB-C Charging Cable', 'Summit Trading', 'Electronics', 'Austin'], ], height: 'auto', colHeaders: true, rowHeaders: true, minRowHeights: 40, manualRowResize: true, autoWrapRow: true, autoWrapCol: true, // licenseKey: 'your-license-key', // get a key at https://handsontable.com/pricing/});</script>
<template> <div id="example1"> <HotTable :settings="hotSettings" /> </div></template>Set row heights with an array
In this example, the height is only set for the first rows. Each additional row would be automatically adjusted to the content.
The rowHeights and minRowHeights arrays and functions address rows by their physical index, so a height stays with its row when rows are moved with ManualRowMove, sorted, filtered, or collapsed with NestedRows. The physical index doesn’t change in any of those cases. A row that NestedRows moves by dragging or detaching takes a new physical index: an array entry follows the row, but a function is called with the new index. When you insert or remove rows, each height of an array stays with its row: a row inserted between others has no height of its own, and a row added after the last one takes the next entry. Handsontable never changes the array you pass. A function is called with the physical index the row has now, so after an insert or a removal it gets the index of the row’s new position. To read the physical index of a row on the screen, use toPhysicalRow().
<script setup lang="ts">import { ref } from 'vue';import { HotTable } from '@handsontable/vue3';import { registerAllModules } from 'handsontable/registry';import type { GridSettings } from 'handsontable/settings';
registerAllModules();
const hotSettings = ref<GridSettings>({ data: [ ['SKU-4821', 'Stainless Steel Water Bottle', 'Harbor Goods', 'Drinkware', 'Seattle'], ['SKU-0093', 'Wireless Mouse', 'Alpine Supply Co.', 'Electronics', 'Denver'], ['SKU-1170', 'Ergonomic Office Chair', 'Cascade Distributors', 'Furniture', 'Portland'], ['SKU-2208', 'USB-C Charging Cable', 'Summit Trading', 'Electronics', 'Austin'], ], width: '100%', height: 'auto', colHeaders: true, rowHeaders: true, minRowHeights: [40, 40, 40, 40], manualRowResize: true, autoWrapRow: true, autoWrapCol: true, // licenseKey: 'your-license-key', // get a key at https://handsontable.com/pricing/});</script>
<template> <div id="example2"> <HotTable :settings="hotSettings" /> </div></template>Set row heights with a function
The row height can be set using a function. In this example, the size of all rows is set using a function that takes a row’s physical index (0, 1, 2 …), adds one, and multiplies the result by 20px, so the first row is 20px high, the second 40px, and so on.
<script setup lang="ts">import { ref } from 'vue';import { HotTable } from '@handsontable/vue3';import { registerAllModules } from 'handsontable/registry';import type { GridSettings } from 'handsontable/settings';
registerAllModules();
const hotSettings = ref<GridSettings>({ data: [ ['SKU-4821', 'Stainless Steel Water Bottle', 'Harbor Goods', 'Drinkware', 'Seattle'], ['SKU-0093', 'Wireless Mouse', 'Alpine Supply Co.', 'Electronics', 'Denver'], ['SKU-1170', 'Ergonomic Office Chair', 'Cascade Distributors', 'Furniture', 'Portland'], ], width: '100%', height: 'auto', colHeaders: true, rowHeaders: true, minRowHeights(index: number) { return (index + 1) * 20; }, manualRowResize: true, autoWrapRow: true, autoWrapCol: true, // licenseKey: 'your-license-key', // get a key at https://handsontable.com/pricing/});</script>
<template> <div id="example3"> <HotTable :settings="hotSettings" /> </div></template>Adjust row heights manually
Set the option manualRowResize to true to allow users to manually resize the row height by dragging the handle between the adjacent row headers. Don’t forget to enable row headers by setting rowHeaders to true.
You can adjust the size of one or multiple rows simultaneously, even if the selected rows are not placed next to each other.
A row resized this way keeps its height, and that height wins over the rowHeights option. To hand control back to the option, pass rowHeights to updateSettings(). That re-declares the heights and discards the stored ones:
// every row is 50px again, including the rows the user draggedhot.updateSettings({ rowHeights: 50 });To resize rows without discarding what the user dragged, leave rowHeights out of the call. To replace the stored heights with your own, pass manualRowResize as an array. You can also clear them yourself with ManualRowResize#clearManualSize() for one row, or clearManualSizes() for all of them, followed by hot.render().
hot.getPlugin('manualRowResize').clearManualSizes();hot.render();<script setup lang="ts">import { ref } from 'vue';import { HotTable } from '@handsontable/vue3';import { registerAllModules } from 'handsontable/registry';import type { GridSettings } from 'handsontable/settings';
registerAllModules();
const hotSettings = ref<GridSettings>({ data: [ ['SKU-4821', 'Stainless Steel Water Bottle', 'Harbor Goods', 'Drinkware', 'Seattle'], ['SKU-0093', 'Wireless Mouse', 'Alpine Supply Co.', 'Electronics', 'Denver'], ['SKU-1170', 'Ergonomic Office Chair', 'Cascade Distributors', 'Furniture', 'Portland'], ['SKU-2208', 'USB-C Charging Cable', 'Summit Trading', 'Electronics', 'Austin'], ['SKU-3341', 'Aluminum Water Filter', 'Northgate Wholesale', 'Drinkware', 'Minneapolis'], ], height: 'auto', colHeaders: true, rowHeaders: true, minRowHeights: 40, manualRowResize: true, autoWrapRow: true, autoWrapCol: true, // licenseKey: 'your-license-key', // get a key at https://handsontable.com/pricing/});</script>
<template> <div id="example4"> <HotTable :settings="hotSettings" /> </div></template>Limit the number of lines in a cell
Long text makes a row taller. To keep rows compact, set the textEllipsis option to a number. Handsontable shows that many lines of text and ends the last visible line with an ellipsis (…). The row grows only up to that number of lines.
textEllipsis value | Result |
|---|---|
false (default) | The text wraps and the row grows to fit all of it. |
true or 1 | The text stays on one line and ends with an ellipsis. |
An integer of 2 or more | The text wraps, but only that many lines are visible. |
Any other number (0, -1, 2.5) | Works like false. |
The truncation only changes how the cell looks. The full text stays in the cell data and in copied data, and the cell editor opens with the full text.
You can set textEllipsis at the grid, column, and cell level, like other cascading options. To override a column for a single cell, return a different value from the cells function.
The autocomplete, dropdown, and handsontable cell types set textEllipsis: true themselves, so a grid-level number does not reach their columns. To show a number of lines in them, set the number on the column (or in cells).
A number works in cells that render plain text, such as the text, numeric, date, time, select, autocomplete, and dropdown cell types. Cells with their own markup, such as cells that use the html renderer, can’t clamp. For them a number works like true: the text stays on one line and ends with an ellipsis.
If you set wordWrap to false, the text can’t wrap. The cell then keeps the text on one line and ends it with an ellipsis, whatever number you set.
In this example, the Note column shows two lines of each note. The rows stay compact, however long the text is. Without textEllipsis, the longest notes would make their rows five lines tall.
<script setup lang="ts">import { ref } from 'vue';import { HotTable } from '@handsontable/vue3';import { registerAllModules } from 'handsontable/registry';import type { GridSettings } from 'handsontable/settings';
registerAllModules();
const hotSettings = ref<GridSettings>({ data: [ ['SKU-4821', 'Stainless Steel Water Bottle', 'Harbor Goods', 'Ships in recyclable packaging. Harbor Goods needs ten days to restock this item, so order early.'], ['SKU-0093', 'Wireless Mouse', 'Alpine Supply Co.', 'Available in black and silver. The silver version is on backorder until the end of the month.'], ['SKU-1170', 'Ergonomic Office Chair', 'Cascade Distributors', 'Assembly required. Cascade Distributors includes a hex key and a printed guide in the box.'], ['SKU-2208', 'USB-C Charging Cable', 'Summit Trading', 'In stock.'], ], colHeaders: ['SKU', 'Product', 'Supplier', 'Note'], colWidths: [100, 190, 170, 220], columns: [ {}, {}, {}, // show two lines of the note and end the second one with an ellipsis { textEllipsis: 2 }, ], width: '100%', height: 'auto', rowHeaders: true, autoRowSize: true, autoWrapRow: true, autoWrapCol: true, // licenseKey: 'your-license-key', // get a key at https://handsontable.com/pricing/});</script>
<template> <div id="example5"> <HotTable :settings="hotSettings" /> </div></template>Related API reference
Configuration options
Core methods
Hooks
Plugins