All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.src.utils.getFacetedUniqueValues.ts Maven / Gradle / Ivy

The newest version!
import { Table, RowData } from '../types'
import { memo } from '../utils'

export function getFacetedUniqueValues(): (
  table: Table,
  columnId: string
) => () => Map {
  return (table, columnId) =>
    memo(
      () => [table.getColumn(columnId)?.getFacetedRowModel()],
      facetedRowModel => {
        if (!facetedRowModel) return new Map()

        let facetedUniqueValues = new Map()

        for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
          const values =
            facetedRowModel.flatRows[i]!.getUniqueValues(columnId)

          for (let j = 0; j < values.length; j++) {
            const value = values[j]!

            if (facetedUniqueValues.has(value)) {
              facetedUniqueValues.set(
                value,
                (facetedUniqueValues.get(value) ?? 0) + 1
              )
            } else {
              facetedUniqueValues.set(value, 1)
            }
          }
        }

        return facetedUniqueValues
      },
      {
        key:
          process.env.NODE_ENV === 'development' &&
          'getFacetedUniqueValues_' + columnId,
        debug: () => table.options.debugAll ?? table.options.debugTable,
        onChange: () => {},
      }
    )
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy