@mui/x-data-grid
Version:
The Community plan edition of the Data Grid components (MUI X).
53 lines • 1.61 kB
JavaScript
import { gridFilteredSortedRowIdsSelector } from "../filter/gridFilterSelector.js";
import { gridRowSpanningHiddenCellsSelector } from "../rows/gridRowSpanningSelectors.js";
export const getLeftColumnIndex = ({
currentColIndex,
firstColIndex,
lastColIndex,
isRtl
}) => {
if (isRtl) {
if (currentColIndex < lastColIndex) {
return currentColIndex + 1;
}
} else if (!isRtl) {
if (currentColIndex > firstColIndex) {
return currentColIndex - 1;
}
}
return null;
};
export const getRightColumnIndex = ({
currentColIndex,
firstColIndex,
lastColIndex,
isRtl
}) => {
if (isRtl) {
if (currentColIndex > firstColIndex) {
return currentColIndex - 1;
}
} else if (!isRtl) {
if (currentColIndex < lastColIndex) {
return currentColIndex + 1;
}
}
return null;
};
export function findNonRowSpannedCell(apiRef, rowId, field, rowSpanScanDirection) {
const rowSpanHiddenCells = gridRowSpanningHiddenCellsSelector(apiRef);
if (!rowSpanHiddenCells[rowId]?.[field]) {
return rowId;
}
const filteredSortedRowIds = gridFilteredSortedRowIdsSelector(apiRef);
// find closest non row spanned cell in the given `rowSpanScanDirection`
let nextRowIndex = filteredSortedRowIds.indexOf(rowId) + (rowSpanScanDirection === 'down' ? 1 : -1);
while (nextRowIndex >= 0 && nextRowIndex < filteredSortedRowIds.length) {
const nextRowId = filteredSortedRowIds[nextRowIndex];
if (!rowSpanHiddenCells[nextRowId]?.[field]) {
return nextRowId;
}
nextRowIndex += rowSpanScanDirection === 'down' ? 1 : -1;
}
return rowId;
}