Referencing the Handsontable instance

优质
小牛编辑
120浏览
2023-12-01

An implementation of the @handsontable/react explaining how to reference the Handsontable instance from the wrapper component.

import React from 'react'; import ReactDOM from 'react-dom'; import {HotTable} from '@handsontable/react'; import Handsontable from 'handsontable'; class App extends React.Component { constructor(props) { super(props); this.id = 'hot'; this.hotSettings = { data: Handsontable.helper.createSpreadsheetData(4, 4), colHeaders: true }; this.hotTableComponent = React.createRef(); } swapHotData() { // The Handsontable instance is stored under the `hotInstance` property of the wrapper component. this.hotTableComponent.current.hotInstance.loadData([['new', 'data']]); } render() { return (
); } } ReactDOM.render(, document.getElementById('example1'));

Edit this page