I’m trying to build a table in React with striped rows, that also has a hover effect on which ever row is moused over.
I’m using the cells
option to configure the striping. And the hooks: afterOnCellMouseOver/afterOnCellMouseOut to add classnames for the hover.
The cells option seems to be overriding the the className being appended by the hooks. Is there another hook I could use to do the striping the would work with the mouseOver/mouseOut?
<HotTable
ref={hotRef}
data={testData}
autoWrapCol={true}
cells={ (row) => {
let cp = {}
if(row % 2 === 0){ cp.className = 'striped'}else{
cp.className = 'unstriped'
}
return cp;
}}
afterOnCellMouseOver={(e, coords, td) => {
let hot = hotRef.current?.hotInstance;
let index = coords.row;
for (let i = 0; i < hot?.countCols(); i++) {
hot?.setCellMeta(index, i, "className", "hovered");
}
hot?.render();
}}
afterOnCellMouseOut={(e, coords, td) => {
let hot = hotRef.current?.hotInstance;
let index = coords.row;
for (let i = 0; i < hot?.countCols(); i++) {
hot?.setCellMeta(index, i, "className", "unhovered");
}
hot?.render();
}}
/>