This page covers a non-latest version of Handsontable.
Row height
Overview By default, the row height adjusts to the height of the content. The minimum height is 23px
. The row height can be passed as a constant
, an array
, or a function
.
The content inside a cell gets wrapped if it doesn't fit the cell's size.
Setting the row height as a constant We set the same height of 40px
for all rows across the entire grid in this example.
Setting the row height in an array In this example, the height is only set for the first rows. Each additional row would be automatically adjusted to the content.
import Handsontable from 'handsontable';
import ReactDOM from 'react-dom';
import { HotTable } from '@handsontable/react';
import { registerAllModules } from 'handsontable/registry';
import 'handsontable/dist/handsontable.full.min.css';
// register Handsontable's modules
registerAllModules();
const ExampleComponent = () => {
return (
<HotTable
data={Handsontable.helper.createSpreadsheetData(4, 5)}
width="100%"
height="auto"
colHeaders={true}
rowHeaders={true}
rowHeights={[40, 40, 40, 40]}
manualRowResize={true}
licenseKey="non-commercial-and-evaluation"
/>
);
};
ReactDOM.render(<ExampleComponent />, document.getElementById('example2'));
<script src="https://cdn.jsdelivr.net/npm/handsontable@12.1/dist/handsontable.full.min.js"></script>
<link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/handsontable@12.1/dist/handsontable.full.min.css" />
<script src="https://cdn.jsdelivr.net/npm/react@17/umd/react.production.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/react-dom@17/umd/react-dom.production.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@handsontable/react@12.1/dist/react-handsontable.js"></script>
<script src="https://handsontable.com/docs/12.1/scripts/fixer.js"></script>
<script src="https://handsontable.com/docs/12.1/scripts/helpers.js"></script>
<div id="example2" class="hot "></div>
Edit in JSFiddle
Setting the row height using 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 index
(1, 2 ...) and multiplies it by 20px
for each consecutive row.
import Handsontable from 'handsontable';
import ReactDOM from 'react-dom';
import { HotTable } from '@handsontable/react';
import { registerAllModules } from 'handsontable/registry';
import 'handsontable/dist/handsontable.full.min.css';
// register Handsontable's modules
registerAllModules();
const ExampleComponent = () => {
return (
<HotTable
data={Handsontable.helper.createSpreadsheetData(3, 5)}
width="100%"
height="auto"
colHeaders={true}
rowHeaders={true}
rowHeights={function(index) {
return (index + 1) * 20;
}}
manualRowResize={true}
licenseKey="non-commercial-and-evaluation"
/>
);
};
ReactDOM.render(<ExampleComponent />, document.getElementById('example3'));
<script src="https://cdn.jsdelivr.net/npm/handsontable@12.1/dist/handsontable.full.min.js"></script>
<link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/handsontable@12.1/dist/handsontable.full.min.css" />
<script src="https://cdn.jsdelivr.net/npm/react@17/umd/react.production.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/react-dom@17/umd/react-dom.production.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@handsontable/react@12.1/dist/react-handsontable.js"></script>
<script src="https://handsontable.com/docs/12.1/scripts/fixer.js"></script>
<script src="https://handsontable.com/docs/12.1/scripts/helpers.js"></script>
<div id="example3" class="hot "></div>
Edit in JSFiddle
Adjust the row height 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.
import Handsontable from 'handsontable';
import ReactDOM from 'react-dom';
import { HotTable } from '@handsontable/react';
import { registerAllModules } from 'handsontable/registry';
import 'handsontable/dist/handsontable.full.min.css';
// register Handsontable's modules
registerAllModules();
const ExampleComponent = () => {
return (
<HotTable
data={Handsontable.helper.createSpreadsheetData(5, 5)}
height="auto"
colHeaders={true}
rowHeaders={true}
rowHeights={40}
manualRowResize={true}
licenseKey="non-commercial-and-evaluation"
/>
);
};
ReactDOM.render(<ExampleComponent />, document.getElementById('example4'));
<script src="https://cdn.jsdelivr.net/npm/handsontable@12.1/dist/handsontable.full.min.js"></script>
<link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/handsontable@12.1/dist/handsontable.full.min.css" />
<script src="https://cdn.jsdelivr.net/npm/react@17/umd/react.production.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/react-dom@17/umd/react-dom.production.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@handsontable/react@12.1/dist/react-handsontable.js"></script>
<script src="https://handsontable.com/docs/12.1/scripts/fixer.js"></script>
<script src="https://handsontable.com/docs/12.1/scripts/helpers.js"></script>
<div id="example4" class="hot "></div>
Edit in JSFiddle
Configuration options:
Core methods:
Hooks:
Plugins:
Last Updated: Nov 20, 2024