Storing number values in string type domain model attribute. HeaderSort Widget Sort them lexicographically instead of numerically.

0
I have created “ItemId” attribute type string in Domain model entity. I am storing number value in this and using HeaderSort Widget to sort this column ascending and descending  in UI. example: ItemID: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 HeaderSort widget sort this column lexicographically instead of numerically attached screen below.   Is there any way to sort this column numerically storing integer values in string attribute in model? Thanks
asked
4 answers
3

Isn’t there the option to store an int or a long? If it’s always only numeric, this seems to be the datatype of choice. If this is, for whatever reason, not an option, you could add a second attribute that stores your value as int/long and use this sexond attribute only for your sorting.

answered
2

This should be a normal behevior bacause if you store anything in a string, then the sort method is  lexicographic. Is there a reason why do you want to store numbers as a string?

I don’t think that there is a way to have the normal features of a grid if you use this case.

answered
0

Prefix each value with spaces before you commit them. ‘  1’, ‘ 11’, ’111’,  ‘ A1’, ‘ A2’ will get sorted ascending in exactly this order. You still run into an issue for A1, A10.

answered
0

Information above was not directly clear for me on how solving the issue Akshay reported initially. After some trial and error I found the following solution below to have an enumeration sort on number from small to big (or the other way around) instead of (1, 10, 11, 2, ...)

answered