Handsontable example
by handsoncode
HTML
<script src="https://cdn.jsdelivr.net/npm/handsontable@13.1/dist/handsontable.full.min.js"></script>
<link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/handsontable@13.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@13.1/dist/react-handsontable.min.js"></script>
<script src="https://handsontable.com/docs/scripts/fixer.js"></script>
<div id="example1" class="hot "></div>
Babel + JSX
import { useRef } from 'react';
import { HotTable } from '@handsontable/react';
import { registerAllModules } from 'handsontable/registry';
import 'handsontable/dist/handsontable.full.min.css';
// register Handsontable's modules
registerAllModules();
export const ExampleComponent = () => {
const ref = useRef(null);
const data = [
['', 'Tesla', 'Nissan', 'Toyota', 'Honda', 'Mazda', 'Ford'],
['2017', 10, 11, 12, 13, 15, 16],
['2018', 10, 11, 12, 13, 15, 16],
['2019', 10, 11, 12, 13, 15, 16],
['2020', 10, 11, 12, 13, 15, 16],
['2021', 10, 11, 12, 13, 15, 16],
];
for (let i = 0; i < 10000; i++) {
data.push(data[i % data.length]);
}
const click = () => {
const wrapper = document.getElementById('wrapper');
if (wrapper.style.visibility !== 'hidden') {
wrapper.style.visibility = 'hidden';
} else {
wrapper.style.visibility = 'visible';
}
console.log(ref.current?.hotInstance.countRenderedRows());
};
return (
<>
<button onClick={click}>Click</button>
<div id="wrapper">
<HotTable
ref={ref}
data={data}
startRows={5}
startCols={5}
height="200px"
width="400px"
colHeaders={true}
minSpareRows={1}
outsideClickDeselects={false}
licenseKey="non-commercial-and-evaluation"
/>
</div>
</>
);
};
ReactDOM.render(<ExampleComponent />, document.getElementById('example1'));