ChemPal Documentation - v1.7.0
    Preparing search index...

    Function getVisibleUniqueValues

    • 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).

      Type Parameters

      • TData

      Parameters

      • column: Column<TData, unknown>

        The column to get values from

      • table: Table<TData>

        The table instance

      Returns (string | number)[]

      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: unknown = row.getValue(column.id);
      if (isStringOrNumber(value)) values.add(value);
      });

      return Array.from(values).sort((a, b) => {
      if (typeof a === 'number' && typeof b === 'number') return a - b;
      return String(a).localeCompare(String(b));
      });
      }