Ordering numbers with Query object

2 posts, 0 answers
  1. Francisco
    Francisco avatar
    3 posts
    Member since:
    Jul 2016

    Posted 28 Jul Link to this post

    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....

  2. Denitsa
    Admin
    Denitsa avatar
    1 posts

    Posted 29 Jul Link to this post

    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.
     
Back to Top