Skip to content

Fix NaN comparisons in DataTables column sorting#3413

Open
Salvialf wants to merge 2 commits into
developfrom
fix/datatable-mixed-column-sort
Open

Fix NaN comparisons in DataTables column sorting#3413
Salvialf wants to merge 2 commits into
developfrom
fix/datatable-mixed-column-sort

Conversation

@Salvialf

@Salvialf Salvialf commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

sortDefault, sortInput, sortSelectValue, sortSelectCustom and sortCustom converted each side of a comparison independently: numeric-looking values became a number, non-numeric values stayed a string. Comparing a number to a non-numeric string coerces the string to NaN, and any comparison against NaN returns false on both sides, which pushes numeric-looking values to one end of the sort regardless of their actual value, instead of sorting them in place among the alphanumeric ones.

The fix only converts both sides to numbers when they are both non-empty and numeric. Otherwise the comparison falls back to strings on both sides, which produces a consistent order for columns mixing numeric-looking and alphabetic values, and preserves the existing numeric sort for columns that are fully numeric.

@Salvialf Salvialf added the changelog-fix Use to generate release notes / changelog To be apply on PR label Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-fix Use to generate release notes / changelog To be apply on PR Need review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant