Row freezing
Lock the position of specified rows, keeping them visible when scrolling.
You can combine frozen rows with frozen columns on both sides of the grid. To freeze all four edges, see Column freezing.
Overview
Row freezing locks specific rows of a grid in place, keeping them visible while scrolling to another area of the grid.
This feature is sometimes called “pinned rows”.
Example
The following example specifies two fixed rows with fixedRowsTop: 2. Horizontal scroll bars are needed, so set a container width and overflow: hidden in CSS.
import Handsontable from 'handsontable/base';import { registerAllModules } from 'handsontable/registry';
// Register all Handsontable's modules.registerAllModules();
// generate an array of arrays with dummy dataconst data = new Array(100) // number of rows .fill(null) .map((_, row) => new Array(50) // number of columns .fill(null) .map((_, column) => `${row}, ${column}`) );
const container = document.querySelector('#example1');
new Handsontable(container, { data, colWidths: 100, width: '100%', height: 320, rowHeaders: true, colHeaders: true, fixedRowsTop: 2, autoWrapRow: true, autoWrapCol: true, // licenseKey: 'your-license-key', // get a key at https://handsontable.com/pricing/});import Handsontable from 'handsontable/base';import { registerAllModules } from 'handsontable/registry';
// Register all Handsontable's modules.registerAllModules();
// generate an array of arrays with dummy dataconst data: string[][] = new Array(100) // number of rows .fill(null) .map((_, row) => new Array(50) // number of columns .fill(null) .map((_, column) => `${row}, ${column}`) );
const container = document.querySelector('#example1')!;
new Handsontable(container, { data, colWidths: 100, width: '100%', height: 320, rowHeaders: true, colHeaders: true, fixedRowsTop: 2, autoWrapRow: true, autoWrapCol: true, // licenseKey: 'your-license-key', // get a key at https://handsontable.com/pricing/});Freeze rows at the bottom
To pin rows to the bottom edge of the grid — sometimes called footer rows — use the fixedRowsBottom option. The specified number of rows stays visible at the bottom of the viewport while you scroll through the rest of the data.
const hot = new Handsontable(container, { data: getData(), // freeze the last two rows as a footer fixedRowsBottom: 2, // licenseKey: 'your-license-key', // get a key at https://handsontable.com/pricing/});You can combine fixedRowsTop and fixedRowsBottom to keep both a header and a footer row in view at the same time.
Freeze rows by dragging
To let users change the number of frozen rows by dragging, enable the freezeBar option. The FreezeBar plugin draws a bar on the edge of the frozen rows, and users drag it to the row boundary where they want the freeze line. The bar also works with the keyboard. Drags are limited to the number of rows that leave room to scroll.
The plugin changes the counts on the grid and doesn’t write them back to the settings you passed in. To keep the counts in your own state, copy them in the afterFreezeChange hook.
Some actions change the counts without afterFreezeChange, such as undo, alter(), and a sheets bar tab switch. See Column freezing: Freeze columns by dragging.
The plugin hides the bars for rows when the Pagination plugin is on, because Pagination doesn’t support frozen rows. For the full guide, see Column freezing: Freeze columns by dragging.
Hidden rows
A row hidden with the HiddenRows plugin keeps its slot in the frozen area. This applies to both fixedRowsTop and fixedRowsBottom. Hiding a row inside the frozen area shrinks the frozen area by that row, and no other row moves in.
- Top rows. The frozen area is always the first
fixedRowsToprows, hidden ones included. WithfixedRowsTop: 3and row 1 hidden, the grid freezes 2 visible rows: rows 0 and 2. A trimmed or filtered row, unlike a hidden one, gives up its slot, so the next row moves in. With row 1 trimmed, the grid still freezes 3 rows: rows 0, 2, and 3. - Bottom rows. The frozen area is always the last
fixedRowsBottomrows, hidden ones included. A trimmed or filtered row gives up its slot.
To keep a set number of visible rows frozen, raise the option by the number of hidden rows inside the frozen area. Hidden columns work the same way. See Column freezing: Hidden columns.
Result
After completing this guide, the rows you specify with fixedRowsTop or fixedRowsBottom stay visible while you scroll through the rest of the grid.
Frozen area size limit
When your grid has a defined height, freeze only as many rows as fit within it.
By default, Handsontable DataGrid draws frozen rows in full. It never shrinks them, and it never scrolls them. If the frozen rows need more space than the grid has, they cover the whole grid. The remaining rows stay out of reach: the vertical scrollbar still moves, but the view no longer changes.
This applies to the total height of the frozen rows, not to how many there are. Taller rows reach the limit sooner. Both fixedRowsTop and fixedRowsBottom behave this way.
To keep the rest of the grid reachable, set the limitFixedToViewport option to true:
fixedRowsTop: 40,fixedRowsBottom: 2,limitFixedToViewport: true,With this option on, Handsontable draws only as many frozen rows as fit and keeps a strip of the grid scrollable. The option changes what the grid draws, not what you configured:
getSettings()still returns the values offixedRowsTopandfixedRowsBottom.- Handsontable measures the grid again when it resizes. The frozen rows come back when the grid grows.
- A strip of at least 40 px stays scrollable.
- The top rows have priority over the bottom rows. When the top rows fill the grid, the bottom rows are not drawn as frozen at all, so rows you pin at the bottom, such as summary rows, can disappear from the frozen area first.
- When a user drags a
FreezeBarbar, the new count replaces the configured one, and the frozen area no longer returns when the grid grows.getFreezeCount()reports the configured count, so an app that saves it keeps the value that was set. - The
FreezeBarplugin shows the bar on the line where the drawn frozen area ends. - Sorting and filtering still treat the rows you configured as frozen. A row that the grid does not draw as frozen stays out of the sort and the filter.
The option works the same way for frozen columns. Read more in Column freezing.
If you leave the option off, keep the combined height of your frozen rows smaller than the grid’s height. If your grid has to work at several sizes, pick a number of frozen rows that fits the shortest one.
Without a defined height, the grid grows to fit its rows, so the frozen rows cannot outgrow it and this limit does not apply. With limitFixedToViewport on, the grid measures the height of the window instead, and draws only the frozen rows that fit in it. Read more in Grid size.
Related API reference
Configuration options
Plugins
Hooks