import{ HotTable }from'@handsontable/react';import{ registerAllModules }from'handsontable/registry';import'handsontable/dist/handsontable.full.min.css';// register Handsontable's modulesregisterAllModules();exportconstExampleComponent=()=>{return(<HotTablelicenseKey="non-commercial-and-evaluation"data={[['A1','B1','C1','D1','E1','F1','G1','H1','I1','J1','K1','L1'],['A2','B2','C2','D2','E2','F2','G2','H2','I2','J2','K2','L2'],['A3','B3','C3','D3','E3','F3','G3','H3','I3','J3','K3','L3'],['A4','B4','C4','D4','E4','F4','G4','H4','I4','J4','K4','L4'],['A5','B5','C5','D5','E5','F5','G5','H5','I5','J5','K5','L5'],]}height="auto"colHeaders={true}rowHeaders={true}hiddenColumns={{columns:[3,5,9],// show UI indicators to mark hidden columnsindicators:true,}}/>);};
Step 3: Set up context menu items
To easily hide and unhide columns, add column hiding items to Handsontable's
context menu.
Enable both the ContextMenu plugin and the
HiddenColumns plugin. Now, the context menu automatically displays
additional items for hiding and unhiding columns.
import{ HotTable }from'@handsontable/react';import{ registerAllModules }from'handsontable/registry';import'handsontable/dist/handsontable.full.min.css';// register Handsontable's modulesregisterAllModules();exportconstExampleComponent=()=>{return(<HotTablelicenseKey="non-commercial-and-evaluation"data={[['A1','B1','C1','D1','E1','F1','G1','H1','I1','J1','K1','L1'],['A2','B2','C2','D2','E2','F2','G2','H2','I2','J2','K2','L2'],['A3','B3','C3','D3','E3','F3','G3','H3','I3','J3','K3','L3'],['A4','B4','C4','D4','E4','F4','G4','H4','I4','J4','K4','L4'],['A5','B5','C5','D5','E5','F5','G5','H5','I5','J5','K5','L5'],]}height="auto"colHeaders={true}rowHeaders={true}// enable the context menucontextMenu={true}// enable the `HiddenColumns` plugin// automatically adds the context menu's column hiding itemshiddenColumns={{columns:[3,5,9],indicators:true,}}/>);};
By default, hidden columns are included in copying and pasting.
To exclude hidden columns from copying and pasting, in the hiddenColumns
object, set the copyPasteEnabled property to false:
import{ HotTable }from'@handsontable/react';import{ registerAllModules }from'handsontable/registry';import'handsontable/dist/handsontable.full.min.css';// register Handsontable's modulesregisterAllModules();exportconstExampleComponent=()=>{return(<HotTablelicenseKey="non-commercial-and-evaluation"data={[['A1','B1','C1','D1','E1','F1','G1','H1','I1','J1','K1','L1'],['A2','B2','C2','D2','E2','F2','G2','H2','I2','J2','K2','L2'],['A3','B3','C3','D3','E3','F3','G3','H3','I3','J3','K3','L3'],['A4','B4','C4','D4','E4','F4','G4','H4','I4','J4','K4','L4'],['A5','B5','C5','D5','E5','F5','G5','H5','I5','J5','K5','L5'],]}height="auto"colHeaders={true}rowHeaders={true}contextMenu={['hidden_columns_show','hidden_columns_hide']}hiddenColumns={{columns:[3,5,9],indicators:true,// exclude hidden columns from copying and pastingcopyPasteEnabled:false,}}/>);};
Column hiding API methods
For the most popular column hiding tasks, use the API methods below.
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.