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
- 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).
- Install a
toString()-based comparator for enum-typed columns so the runtime behaviour matches the documented "Alphabetical".
References
Summary
SPECIFICATIONS.md§2.2 (Type-to-Renderer Mapping) lists the Sorting forEnum<?>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,
EasyGridinstalls an in-memory comparator built from the column'sValueProviderwhenever the value type isComparableor a primitive (EasyGridWrapper#createEasyColumn):EnumimplementsComparable, so enum columns receive a natural-order comparator and therefore sort byordinal()— not alphabetically.(Enum rendering is correct per spec: it uses
Enum.toString(), notEnum.name().)Expected vs. actual
Options
LOW < MEDIUM < HIGH).toString()-based comparator for enum-typed columns so the runtime behaviour matches the documented "Alphabetical".References
SPECIFICATIONS.md§2.2 —Enum<?>row, Sorting = AlphabeticalEasyGridWrapper#createEasyColumn— comparator wiringIMPLEMENTATION_ANALYSIS.md