UNPKG

@tanstack/table-core

Version:

Headless UI for building powerful tables & datagrids for TS/JS.

51 lines (50 loc) 1.59 kB
//#region src/worker/serializeRowModel.ts function isCloneSafe(value) { return typeof value !== "function" && typeof value !== "symbol"; } function serializeRows(rows, coreIndexById, aggregateColumnIds) { const nodes = new Array(rows.length); for (let i = 0; i < rows.length; i++) { const row = rows[i]; if (row.groupingColumnId == null) { nodes[i] = coreIndexById[row.id]; continue; } const aggregates = {}; for (let c = 0; c < aggregateColumnIds.length; c++) { const columnId = aggregateColumnIds[c]; const value = row.getValue(columnId); if (value !== void 0 && isCloneSafe(value)) aggregates[columnId] = value; } if (!(row.groupingColumnId in aggregates)) { const value = row.getValue(row.groupingColumnId); if (value !== void 0 && isCloneSafe(value)) aggregates[row.groupingColumnId] = value; } nodes[i] = { id: row.id, groupingColumnId: row.groupingColumnId, groupingValue: row.groupingValue, index: row.index, aggregates, children: serializeRows(row.subRows, coreIndexById, aggregateColumnIds) }; } return nodes; } function serializeRowModel(model, coreIndexById, aggregateColumnIds, transfer) { if (model.flatRows.length === model.rows.length) { const indices = new Uint32Array(model.rows.length); for (let i = 0; i < indices.length; i++) indices[i] = coreIndexById[model.rows[i].id]; transfer.push(indices.buffer); return { kind: "flat", indices }; } return { kind: "tree", children: serializeRows(model.rows, coreIndexById, aggregateColumnIds) }; } //#endregion export { serializeRowModel };