This page covers a non-latest version of Handsontable.
Row hiding
Hide your rows, using the HiddenRows
plugin.
About row hiding "Hiding a row" means that the hidden row doesn't get rendered as a DOM element.
When you're hiding a row:
The source data doesn't get modified. The HiddenRows
plugin doesn't participate in data transformation (the shape of the data returned by the getData*()
methods stays intact). Enabling row hiding To simply enable row hiding (without further configuration), set the hiddenRows
configuration option to true
:
Setting up row hiding To set up your row hiding configuration, follow the steps below.
Step 1: Specify rows hidden by default To both enable row hiding and specify rows hidden by default, set the hiddenRows
configuration option to an object.
In the object, add a rows
property, and set it to an array of row indexes.
Now, those rows are hidden by default:
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
licenseKey="non-commercial-and-evaluation"
data={Handsontable.helper.createSpreadsheetData(12, 5)}
height="auto"
colHeaders={true}
rowHeaders={true}
hiddenRows={{
// specify rows hidden by default
rows: [3, 5, 9]
}}
/>
);
};
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
Step 2: Show UI indicators To easily see which rows are currently hidden, display UI indicators.
To enable the UI indicators, in the hiddenRows
object, set the indicators
property to true
:
TIP
If you use both the NestedHeaders
plugin and the HiddenRows
plugin, you also need to set the colHeaders
property to true
. Otherwise, indicators
won't work.
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
licenseKey="non-commercial-and-evaluation"
data={Handsontable.helper.createSpreadsheetData(12, 5)}
height="auto"
colHeaders={true}
rowHeaders={true}
hiddenRows={{
rows: [3, 5, 9],
// show UI indicators to mark hidden rows
indicators: true
}}
/>
);
};
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
To easily hide and unhide rows, add row hiding items to Handsontable's context menu .
Enable both the ContextMenu
plugin and the HiddenRows
plugin. Now, the context menu automatically displays additional items for hiding and unhiding rows.
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
licenseKey="non-commercial-and-evaluation"
data={Handsontable.helper.createSpreadsheetData(12, 5)}
height="auto"
colHeaders={true}
rowHeaders={true}
contextMenu={true}
hiddenRows={{
rows: [3, 5, 9],
indicators: true
}}
/>
);
};
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
You can also add the row hiding menu items individually, by adding the hidden_rows_show
and hidden_rows_hide
strings to the contextMenu
parameter:
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
licenseKey="non-commercial-and-evaluation"
data={Handsontable.helper.createSpreadsheetData(12, 5)}
height="auto"
colHeaders={true}
rowHeaders={true}
contextMenu={[`hidden_rows_show`, `hidden_rows_hide`]}
hiddenRows={{
rows: [3, 5, 9],
indicators: true
}}
/>
);
};
ReactDOM.render(<ExampleComponent />, document.getElementById('example5'));
<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="example5" class="hot "></div>
Edit in JSFiddle
Step 4: Set up copy and paste behavior By default, hidden rows are included in copying and pasting.
To exclude hidden rows from copying and pasting, in the hiddenRows
object, set the copyPasteEnabled
property to false
:
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
licenseKey="non-commercial-and-evaluation"
data={Handsontable.helper.createSpreadsheetData(12, 5)}
height="auto"
colHeaders={true}
rowHeaders={true}
contextMenu={[`hidden_rows_show`, `hidden_rows_hide`]}
hiddenRows={{
rows: [3, 5, 9],
indicators: true,
// exclude hidden rows from copying and pasting
copyPasteEnabled: false
}}
/>
);
};
ReactDOM.render(<ExampleComponent />, document.getElementById('example6'));
<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="example6" class="hot "></div>
Edit in JSFiddle
Row hiding API methods
TIP
To use the Handsontable API, you'll need access to the Handsontable instance. You can do that by utilizing a reference to the HotTable
component, and reading its hotInstance
property.
For more information, see the Instance Methods
page.
For the most popular row hiding tasks, use the API methods below.
To see your changes, re-render your Handsontable instance with the render()
method.
Accessing the HiddenRows
plugin instance To access the HiddenRows
plugin instance, use the getPlugin()
method:
Hiding a single row To hide a single row, use the hideRow()
method:
Hiding multiple rows To hide multiple rows:
Either pass row indexes as arguments to the hideRow()
method Or pass an array of row indexes to the hideRows()
method Unhiding a single row To unhide a single row, use the showRow()
method:
Unhiding multiple rows To unhide multiple rows:
Either pass row indexes as arguments to the showRow()
method Or pass an array of row indexes to the showRows()
method Configuration options:
Hooks:
Plugins: