@tanstack/table-core
Version:
Headless UI for building powerful tables & datagrids for TS/JS.
40 lines (36 loc) • 1.38 kB
JavaScript
/**
* table-core
*
* Copyright (c) TanStack
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
;
var utils = require('../utils.js');
function getFacetedUniqueValues() {
return (table, columnId) => utils.memo(() => {
var _table$getColumn;
return [(_table$getColumn = table.getColumn(columnId)) == null ? void 0 : _table$getColumn.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)) {
var _facetedUniqueValues$;
facetedUniqueValues.set(value, ((_facetedUniqueValues$ = facetedUniqueValues.get(value)) != null ? _facetedUniqueValues$ : 0) + 1);
} else {
facetedUniqueValues.set(value, 1);
}
}
}
return facetedUniqueValues;
}, utils.getMemoOptions(table.options, 'debugTable', `getFacetedUniqueValues_${columnId}`));
}
exports.getFacetedUniqueValues = getFacetedUniqueValues;
//# sourceMappingURL=getFacetedUniqueValues.js.map