Message:

Subscribe rss
Blog categories
All | Backendless features
Feature 47: Loading data objects from server with sorting
February 24, 2015 by markpiller
Spread the love

In one of my previous posts I wrote about how to load data from the Backendless mbaas server using paging. In fact, data paging is only one of the features available in the data loading API. In this post I am going to show how to fetch data objects with sorting. The sorting option can be combined with any other data loading feature. For example, you could have both sorting and the “where clause” in your data loading request. For this example, I am going to use the Restaurant-to-go app schema.

Here’s what my data in the Restaurant table looks like:
restaurant table with data - Feature 47: Loading data objects from server with sorting

Consider the Restaurant class below. When my code fetches data from the server, it will arrive as a collection of the Restaurant class instances:

The class declares public fields, however, it could’ve been written as a Java bean (that is with public getters and setters). The Backendless SDK for Java/Android can work either one of the approaches.

The code below loads the restaurant objects sorted in the ascending order by the “created” column/field. The ascending order is requested by the “ASC” qualifier.

Asynchronous sample (Plain Java and Android):

Synchronous sample (Plain Java only):

The code produces the following output – the objects are sorted by the “created” column:

Enjoy!

 

Share this post
Tweet about this on TwitterShare on FacebookGoogle+