Skip to content

Instantly share code, notes, and snippets.

@romgrk
Created December 3, 2024 02:53
Show Gist options
  • Save romgrk/7f7a682578a1c5f2bbcd8b82aef3148e to your computer and use it in GitHub Desktop.
Save romgrk/7f7a682578a1c5f2bbcd8b82aef3148e to your computer and use it in GitHub Desktop.
const focusedVirtualCellSelector = createSelectorMemoizedV8(
gridRenderContextSelector,
gridFocusCellSelector,
currentRowsSelector,
visibleColumnsSelector,
(currentRenderContext, focusedCell, currentRows, visibleColumns) => {
if (!focusedCell) {
return null;
}
const rowIndex = currentRows.findIndex((row) => row.id === focusedCell.id);
const columnIndex = visibleColumns.findIndex((column) => column.field === focusedCell.field);
if (rowIndex === -1 || columnIndex === -1) {
return null;
}
const isFocusedCellInContext =
rowIndex >= currentRenderContext.firstRowIndex &&
rowIndex <= currentRenderContext.lastRowIndex &&
columnIndex >= currentRenderContext.firstColumnIndex &&
columnIndex <= currentRenderContext.lastColumnIndex;
if (isFocusedCellInContext) {
return null;
}
return {
...focusedCell,
rowIndex,
columnIndex,
};
},
);
// usage
const focusedVirtualCell = useGridSelectorV8(apiRef, focusedVirtualCellSelector)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment