Sorting

Telerik Platform can return query results in sorted order: ascending or descending. All processing is performed on the server, saving you the additional operations on the client.

Use the X-Everlive-Sort header to pass a JSON object containing the property that you want to sort by and the sorting order: 1 for ascending and -1 for descending.

In this article:

Ascending

You can retrieve items sorted in ascending order by a field. The following example reads all items from Books before returning them sorted by Author.

Request:
    GET https://api.everlive.com/v1/your-app-id/Books
Headers:
    Authorization  Bearer your-access-token
    X-Everlive-Sort { "Author" : 1 }

Response:
    Status: 200 OK
    Content-Type: application/json
var sortExp = { "Author" : 1 };

//Ajax request using jQuery
$.ajax({
    url: 'https://api.everlive.com/v1/your-app-id/Books',
    type: "GET",
    headers: {
        "Authorization" : "Bearer your-access-token",
        "X-Everlive-Sort" : JSON.stringify(sortExp)
    },
    success: function(data){
        alert(JSON.stringify(data));
    },
    error: function(error){
        alert(JSON.stringify(error));
    }
});

Descending

To request sorting in descending order, use -1 in the X-Everlive-Sort header.

Request:
    GET https://api.everlive.com/v1/your-app-id/Books
Headers:
    Authorization  Bearer your-access-token
    X-Everlive-Sort { "Author" : -1 }

Response:
    Status: 200 OK
    Content-Type: application/json
var sortExp = { "Author" : -1 };

//Ajax request using jQuery
$.ajax({
    url: 'https://api.everlive.com/v1/your-app-id/Books',
    type: "GET",
    headers: {
        "Authorization" : "Bearer your-access-token",
        "X-Everlive-Sort" : JSON.stringify(sortExp)
    },
    success: function(data){
        alert(JSON.stringify(data));
    },
    error: function(error){
        alert(JSON.stringify(error));
    }
});

Multiple Fields

When retrieving more elaborate data structures, you may need to sort by multiple fields. To do that, specify a comma-separated list of the fields that you want to sort by, starting with the primary.

The following example reads all items from the Books content type and returns them sorted first by date of birth of the authors and then by author name.

Request:
    GET https://api.everlive.com/v1/your-app-id/Books
Headers:
    Authorization  Bearer your-access-token
    X-Everlive-Sort { "DateOfBirth" : 1, "Author" : 1 }

Response:
    Status: 200 OK
    Content-Type: application/json
var sortExp = { "DateOfBirth" : 1, "Author" : 1 };

//Ajax request using jQuery
$.ajax({
    url: 'https://api.everlive.com/v1/your-app-id/Books',
    type: "GET",
    headers: {
        "Authorization" : "Bearer your-access-token",
        "X-Everlive-Sort" : JSON.stringify(sortExp)
    },
    success: function(data){
        alert(JSON.stringify(data));
    },
    error: function(error){
        alert(JSON.stringify(error));
    }
});

See Also

Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.