This is a migrated thread and some comments may be shown as answers.

Ordering numbers with Query object

1 Answer 31 Views
JavaScript SDK
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Francisco
Top achievements
Rank 1
Francisco asked on 28 Jul 2016, 05:04 PM

Hi!

I'm trying to sorting a "price" field (it's a Number field), but when I do:

query.order('price');

It considere the 'price' as string, so, instead of get this: 10, 20, 100, 200 .... I get 10, 100, 20, 200.

I think it's because it considers the numbers as strings, then it looks at the first "character" and put back "10" and "100" first, and "20" and "200" after...

Is there a way to make the order() function orders as numbers not as strings?

thank you and sorry for my english....

1 Answer, 1 is accepted

Sort by
0
Denitsa
Telerik team
answered on 29 Jul 2016, 03:01 PM
Hi,

The code you provided should work fine.

Generally, the sorting functionality provides correct results when the field is of type Number. The behavior you observed is not correct. It is probable that there are items whose Price field is not a number but a string. Could you please check for such items?

Even though, the Price field is chosen to be of type Number, Backend services does not enforce any validation for the type of the value. Currently, these types are used for UI purposes only.

More information about data and data types could be found here: http://docs.telerik.com/platform/backend-services/javascript/data/introduction

I hope this helps.

Regards,
Denitsa
Telerik by Progress
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
Tags
JavaScript SDK
Asked by
Francisco
Top achievements
Rank 1
Answers by
Denitsa
Telerik team
Share this question
or