TOPIC: Sorting by a field
#943
Sorting by a field 3 Years, 1 Month ago
I have a field where the values (Lot Numbers) range from 1 to 133. I wanted to sort a report based on those numbers, but the sort goes something like 1,10,11,100,101,... I don't know, not the traditional 1,2,3,...

The archived forum posts discussed this issue, but the answer was not clear to me. So I created a computed field, lotString, based on the lot number, lotNumber, where a rule defines lotString as return .lotNumber.LeftFill(3,'0'). I sort on this field, 001,002,...,100,101,... even though I don't print it.
 
 
#944
Re:Sorting by a field 3 Years, 1 Month ago
It depends whether your values are being stored as numbers or strings. Look at your table in QueryView - if the values have quotes then they are strings and that is why they are not sorting as numbers.

You can convert existing data from QueryView using something like:

update mytable set myfield = Number(myfield)

If the values are typed in by the user, then you need to make sure you are using a NumberControl, not just a FieldControl. (Normally you do this by creating a Field_ definition.)

If you are assigning the numbers in your code, then you need to make sure you are assigning numbers, not strings.
 
 
andrew
 
#947
Re:Sorting by a field 3 Years, 1 Month ago
OK. That solves it. Thanks.