Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

natural sorting #2275

Open
aradi222 opened this issue Aug 26, 2022 · 2 comments
Open

natural sorting #2275

aradi222 opened this issue Aug 26, 2022 · 2 comments

Comments

@aradi222
Copy link

I'm looking for the easiest way to sort a Jtable column that consists of numbers and text, and a combination of these.

E.g.

'1B1'
'1A2'
'1A100'
'1A1'
'1A10'

turns into (correct)

'1A1'
'1A2'
'1A10'
'1A100'
'1B1'

Jtable sorts like this: (wrong)

'1A1'
'1A10'
'1A100'
'1A2'

thank you

@misterparsons
Copy link

JTable does NOT do any sorting, it passes the header clicks to the server with a load request and parameter jtSorting set to a string like "colName ASC/DESC" for the server to perform the sort. In my experience this is usually in the database, so your post is really an SQL question. You may get better answers on a SQL forum.
I use mySQL which has no natural sorting features, but stackoverflow is full of niche solutions, that you might find useful.

@reposankar
Copy link

Looks like @aradi222 is looking for number sorting for the string values. That can be possible if you manage to have clear logic to segregate numbers from string values (think the data always have the first two characters to be ignored for number sorting, take it from third char till end ex: oracle TO_NUMBER(SUBSTR('1A100', 3)) then use for sorting the entire expression in the order by clause of the database query might help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants