A sorted array of unique values
export function getVisibleUniqueValues<TData>(
column: Column<TData, unknown>,
table: Table<TData>,
): (string | number)[] {
const values = new Set<string | number>();
table.getRowModel().rows.forEach((row) => {
const value = row.getValue(column.id);
if (value !== undefined && value !== null) values.add(value as string | number);
});
return Array.from(values).sort((a, b) => {
if (typeof a === "number" && typeof b === "number") return a - b;
return String(a).localeCompare(String(b));
});
}
Gets a sorted unique list of values for a column from visible rows. Only returns the visible values (e.g., if another filter has been applied, the filtered out results won't be included here).