Skip to content

Enum columns sort by ordinal (natural) order, not alphabetically as documented #13

@javier-godoy

Description

@javier-godoy

Summary

SPECIFICATIONS.md §2.2 (Type-to-Renderer Mapping) lists the Sorting for Enum<?> columns as "Alphabetical", but the implementation sorts enum columns by the enum's natural order (Enum.compareTo, i.e. declaration / ordinal() order). The two only coincide when the constants happen to be declared in alphabetical order.

Details

For sortable columns, EasyGrid installs an in-memory comparator built from the column's ValueProvider whenever the value type is Comparable or a primitive (EasyGridWrapper#createEasyColumn):

if (Comparable.class.isAssignableFrom(type) || type.isPrimitive()) {
  column.setComparator((ValueProvider) getter);
}

Enum implements Comparable, so enum columns receive a natural-order comparator and therefore sort by ordinal() — not alphabetically.

(Enum rendering is correct per spec: it uses Enum.toString(), not Enum.name().)

Expected vs. actual

  • Expected (spec §2.2): enum columns sort alphabetically.
  • Actual: enum columns sort in declaration / ordinal order.

Options

  1. Update the spec to state that enums sort in natural (declaration) order. Least work, and often the more useful behaviour (e.g. LOW < MEDIUM < HIGH).
  2. Install a toString()-based comparator for enum-typed columns so the runtime behaviour matches the documented "Alphabetical".

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions