UNPKG

@dgit/react-data-grid-addons

Version:

A set of addons for react-data-grid

48 lines (40 loc) 1.2 kB
import {List} from 'immutable'; import groupBy from 'lodash/groupBy'; import { utils } from 'react-data-grid'; const { getMixedTypeValueRetriever, isImmutableMap } = utils; export default class RowGrouperResolver { constructor(isImmutable) { this.isImmutable = isImmutable; this.getRowObj = getMixedTypeValueRetriever(isImmutable).getValue; } initRowsCollection() { return this.isImmutable ? new List() : []; } getGroupedRows(rows, columnName) { return this.isImmutable ? rows.groupBy(x => isImmutableMap(x) ? x.get(columnName) : x[columnName]) : groupBy(rows, columnName); } getGroupKeys(groupedRows) { let getKeys = Object.keys; if (this.isImmutable) { getKeys = (col) => { let keys = []; let iterator = col.keys(); let item = iterator.next(); while (!item.done) { keys.push(item.value); item = iterator.next(); } return keys; }; } return getKeys(groupedRows); } addHeaderRow(rowGroupHeader, dataviewRows) { let rows = dataviewRows; let dvRows = rows.push(rowGroupHeader); if (this.isImmutable) { return dvRows; } return rows; } }