Search code examples
javaandroidsortingcollectionsparse-server

Sort Parse collection in ascending order by value of class column


I would like to query a class, Inventory, wherein the objects contained have a column called "groupNumber". This groupNumber assigns each of the Inventory objects to a group, naturally. The idea then is to sort this list according to group number, where the first Inventory object with groupNumber 1 will be at the top of the list, the second will be below it, then the first Inventory objects of groupNumber 2, etc.

ParseQuery<ParseObject> inventoryQuery = new ParseQuery<ParseObject>("Inventory");
inventoryQuery.orderByAscending("groupNumber");

Example Data:

Inventory object - groupNumber
Item1 - 1
Item6 - 1
Item10 - 1
Item4 - 2
Item5 -2
Item8 - 3
Item2 - 3
Item7 - 4
Item9 - 5
Item3 - 5

Can I sort this in the same that I can sort by createdAt, for example?


Solution

  • try this one

    ParseQuery<ParseObject> inventoryQuery = new ParseQuery<ParseObject>("Inventory");
    inventoryQuery.addAscendingOrder("groupNumber");
    inventoryQuery.addDescendingOrder("createdAt");
    

    it will sort "groupNumber" by ascending, then sort "createdAt"

    priority depends on the order you use "addXXXXOrder".