Hello, I am trying to store last selected row index in local storage. As we have tabs, users navigate between them, they are separate components. In one of them we use handsontable. What we want to achieve is to make a grid highlight row using saved value from localstorage.
const highlightSelectedJobRow = (row, column) => {
for (var i = 0; i < hotTableComponent.current.hotInstance.countCols(); i++) {
hotTableComponent.current.hotInstance.setCellMeta(row, i, 'className', 'currentRow');
}
localStorage.setItem('lastHighlitedRow', row);
hotTableComponent.current.hotInstance.render();
}
const getHighlightedRow = () => {
if (localStorage.hasOwnProperty("lastHighlitedRow")) {
let lastHighlitedRow = localStorage.getItem('lastHighlitedRow');
for (var i = 0; i < hotTableComponent.current.hotInstance.countCols(); i++) {
hotTableComponent.current.hotInstance.setCellMeta(lastHighlitedRow, i, 'className', 'currentRow');
}
hotTableComponent.current.hotInstance.render();
}
getHighlightedRow method is called in UseEffect hook(React)
Code works. For some reason I have to click somewhere on grid then last selected row will be highlighted. I need to elaminate this behavior.