@mui/x-data-grid-pro
Version:
The Pro plan edition of the MUI X Data Grid components.
66 lines (65 loc) • 2.37 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.findSkeletonRowsSection = exports.adjustRowParams = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _xDataGrid = require("@mui/x-data-grid");
/**
* Adjusts the row fetch parameters to align with page boundaries.
* - Start index is decreased to the start of the page
* - End index is increased to the end of the page (capped by rowCount - 1 if defined)
*/
const adjustRowParams = (params, options) => {
if (typeof params.start !== 'number') {
return params;
}
const {
pageSize,
rowCount
} = options;
const adjustedStart = params.start - params.start % pageSize;
const pageAlignedEnd = params.end + pageSize - params.end % pageSize - 1;
// rowCount of -1 means "unknown/infinite", treat same as undefined (no capping)
const maxEnd = rowCount !== undefined && rowCount !== -1 ? Math.max(0, rowCount - 1) : Infinity;
return (0, _extends2.default)({}, params, {
start: adjustedStart,
end: Math.min(maxEnd, pageAlignedEnd)
});
};
exports.adjustRowParams = adjustRowParams;
const findSkeletonRowsSection = ({
apiRef,
visibleRows,
range
}) => {
let {
firstRowIndex,
lastRowIndex
} = range;
const visibleRowsSection = visibleRows.slice(range.firstRowIndex, range.lastRowIndex);
let startIndex = 0;
let endIndex = visibleRowsSection.length - 1;
let isSkeletonSectionFound = false;
while (!isSkeletonSectionFound && firstRowIndex < lastRowIndex) {
const isStartingWithASkeletonRow = (0, _xDataGrid.gridRowNodeSelector)(apiRef, visibleRowsSection[startIndex].id)?.type === 'skeletonRow';
const isEndingWithASkeletonRow = (0, _xDataGrid.gridRowNodeSelector)(apiRef, visibleRowsSection[endIndex].id)?.type === 'skeletonRow';
if (isStartingWithASkeletonRow && isEndingWithASkeletonRow) {
isSkeletonSectionFound = true;
}
if (!isStartingWithASkeletonRow) {
startIndex += 1;
firstRowIndex += 1;
}
if (!isEndingWithASkeletonRow) {
endIndex -= 1;
lastRowIndex -= 1;
}
}
return isSkeletonSectionFound ? {
firstRowIndex,
lastRowIndex
} : undefined;
};
exports.findSkeletonRowsSection = findSkeletonRowsSection;