@tanstack/table-core
Version:
Headless UI for building powerful tables & datagrids for TS/JS.
61 lines (57 loc) • 1.67 kB
JavaScript
/**
* table-core
*
* Copyright (c) TanStack
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
;
var utils = require('../utils.js');
var getExpandedRowModel = require('./getExpandedRowModel.js');
function getPaginationRowModel(opts) {
return table => utils.memo(() => [table.getState().pagination, table.getPrePaginationRowModel(), table.options.paginateExpandedRows ? undefined : table.getState().expanded], (pagination, rowModel) => {
if (!rowModel.rows.length) {
return rowModel;
}
const {
pageSize,
pageIndex
} = pagination;
let {
rows,
flatRows,
rowsById
} = rowModel;
const pageStart = pageSize * pageIndex;
const pageEnd = pageStart + pageSize;
rows = rows.slice(pageStart, pageEnd);
let paginatedRowModel;
if (!table.options.paginateExpandedRows) {
paginatedRowModel = getExpandedRowModel.expandRows({
rows,
flatRows,
rowsById
});
} else {
paginatedRowModel = {
rows,
flatRows,
rowsById
};
}
paginatedRowModel.flatRows = [];
const handleRow = row => {
paginatedRowModel.flatRows.push(row);
if (row.subRows.length) {
row.subRows.forEach(handleRow);
}
};
paginatedRowModel.rows.forEach(handleRow);
return paginatedRowModel;
}, utils.getMemoOptions(table.options, 'debugTable', 'getPaginationRowModel'));
}
exports.getPaginationRowModel = getPaginationRowModel;
//# sourceMappingURL=getPaginationRowModel.js.map