@mui/x-data-grid-pro
Version:
The Pro plan edition of the MUI X Data Grid components.
32 lines (31 loc) • 1.47 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useGridInfiniteLoader = void 0;
var _xDataGrid = require("@mui/x-data-grid");
var _internals = require("@mui/x-data-grid/internals");
var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallback"));
/**
* @requires useGridColumns (state)
* @requires useGridDimensions (method) - can be after
* @requires useGridScroll (method
*/
const useGridInfiniteLoader = (apiRef, props) => {
const visibleColumns = (0, _xDataGrid.useGridSelector)(apiRef, _xDataGrid.gridVisibleColumnDefinitionsSelector);
const currentPage = (0, _internals.useGridVisibleRows)(apiRef, props);
const isEnabled = props.rowsLoadingMode === 'client' && !!props.onRowsScrollEnd;
const handleLoadMoreRows = (0, _useEventCallback.default)(() => {
const viewportPageSize = apiRef.current.getViewportPageSize();
const rowScrollEndParams = {
visibleColumns,
viewportPageSize,
visibleRowsCount: currentPage.rows.length
};
apiRef.current.publishEvent('rowsScrollEnd', rowScrollEndParams);
});
(0, _xDataGrid.useGridEventPriority)(apiRef, 'rowsScrollEnd', props.onRowsScrollEnd);
(0, _xDataGrid.useGridEvent)(apiRef, 'rowsScrollEndIntersection', (0, _internals.runIf)(isEnabled, handleLoadMoreRows));
};
exports.useGridInfiniteLoader = useGridInfiniteLoader;
;