package.src.utils.getFacetedUniqueValues.ts Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of table-core Show documentation
Show all versions of table-core Show documentation
Headless UI for building powerful tables & datagrids for TS/JS.
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