UNPKG

@etsoo/materialui

Version:

TypeScript Material-UI Implementation

59 lines (58 loc) 1.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MUUtils = void 0; /** * MU utilities */ var MUUtils; (function (MUUtils) { /** * Get grid data * @param grid Grid * @param checkField Check field or callback * @returns Results */ function getGridData(grid, checkField) { const check = typeof checkField === "function" ? checkField : (item) => { const value = item[checkField]; return value == null || value === "" ? false : true; }; const items = []; for (const [_, value] of grid.getRowModels()) { const item = value; if (check(item)) { items.push(item); } } return items; } MUUtils.getGridData = getGridData; /** * Setup paging keysets * @param data Paging data * @param lastItem Last item of the query * @param idField Id field */ function setupPagingKeysets(data, lastItem, idField) { // If the id field is not set for ordering, add it with descending if (typeof data.queryPaging === "object") { const orderBy = (data.queryPaging.orderBy ??= []); const idUpper = idField.toUpperCase(); if (!orderBy.find((o) => o.field.toUpperCase() === idUpper)) { orderBy.push({ field: idField, desc: true, unique: true }); } // Set the paging keysets if (lastItem) { const keysets = orderBy.map((o) => Reflect.get(lastItem, o.field)); data.queryPaging.keysets = keysets; } else { data.queryPaging.keysets = undefined; } } return data; } MUUtils.setupPagingKeysets = setupPagingKeysets; })(MUUtils || (exports.MUUtils = MUUtils = {}));