How can I order a Column where the type is text, but all the values stored are numeric,

I want to order it descending but considering the Column a Numeric field without changing the column type

Thank you

  • Even as text, numbers are treated correctly for purposes of ordering. – BigRaj Jun 29 '19 at 21:10
  • so, should I only change the Type to "numeric" instead of text in the camlquery ? <Value Type='Text'> , cause currently my results are in the following order: 1,11,19,2,20,3,30 – Mike Jun 29 '19 at 21:28
  • The trick is to add leading 0’s. 01,02,03...10,11,12. If it gets to the 100’s, you’ll need to add 2 leading 0’s. 001,002,003...010011,012...100. Keep the type of ‘text’ – BigRaj Jun 30 '19 at 22:06
  • I think i'll go with a calculated column as we can't modify the column data. Thank you! – Mike Jul 1 '19 at 4:44

There is no way to do this using CAML.

You'd need to fetch the results then sort using JavaScript.

|improve this answer|||||

So This was my solution :

I created a Calculated column based on the original column with output type as numeric

There was a problem though. the calculated column at the beginning was returning the result as text too.

To fix this issue I had to do the following :

1.- ad a +"0" to the formula

I don't know how or why this worked, but doing this it transformed all the items into numeric.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.