Babel + JSX
import { HotTable } from '@handsontable/react-wrapper';
import { registerAllModules } from 'handsontable/registry';
import 'handsontable/styles/handsontable.css';
import 'handsontable/styles/ht-theme-main.css';
// register Handsontable's modules
registerAllModules();
const setColumnHeader = (_, TH) => {
TH.classList.add('bold')
}
const updateTableWidthContainer = (hot) => {
if (!hot) return
const SCROLLBAR_MARGIN = 14
const wtHider = hot.rootElement.querySelector('.wtHider')
if (wtHider) {
hot.updateSettings({
width: wtHider.clientWidth + SCROLLBAR_MARGIN,
})
}
}
const ExampleComponent = () => {
const hotRef = React.useRef(null)
React.useEffect(() => {
const hot = hotRef.current?.hotInstance
if (!hot) return
requestAnimationFrame(() => updateTableWidthContainer(hot))
}, [])
return (
<HotTable
themeName="ht-theme-main"
data={[
['', 'Tesla', 'Volvo', 'Toyota', 'Ford', 'FAW'],
['2019', 10, 11, 12, 13, 14],
['2019', 10, 11, 12, 13, 14],
['2019', 10, 11, 12, 13, 14],
['2019', 10, 11, 12, 13, 14],
['2019', 10, 11, 12, 13, 14],
['2019', 10, 11, 12, 13, 14],
['2019', 10, 11, 12, 13, 14],
['2019', 10, 11, 12, 13, 14],
['2019', 10, 11, 12, 13, 14],
['2019', 10, 11, 12, 13, 14],
['2019', 10, 11, 12, 13, 14],
['2019', 10, 11, 12, 13, 14],
['2019', 10, 11, 12, 13, 14],
['2019', 10, 11, 12, 13, 14],
['2019', 10, 11, 12, 13, 14],
]}
rowHeaders={true}
colHeaders={true}
height="300"
autoWrapRow={true}
autoWrapCol={true}
licenseKey="non-commercial-and-evaluation"
afterGetColHeader={setColumnHeader}
afterInit={function (this) {
updateTableWidthContainer(this)
}}
/>
);
};
const container = document.getElementById("example");
const root =...