I am using SP.CamlQuery.createAllItemsQuery() to grab all items from a custom list in SharePoint, however even though the list itself is sorted in an alphabetical order, when it comes through to a select tag in the html webpart it comes in the order the items were added to the list (I assume it's sorted by ID) How can I make it sort alphabetically to make the list easier to read for the user?

1 Answer 1


If you want the data to be retrieved in specific order then you cannot use createAllItemsquery as it does not create query based on any existing views on the list. Instead you should include a caml query with specific sort order.

a) To get items based on existing view on a list, please refer to this answer

b) To retrieve items based on specific query use below example. Note the order by clause is included to sort items by modified date.

var query = 
<View Scope='RecursiveAll'>

             <FieldRef Name='Modified' Ascending='False' />
var camlQuery = new SP.CamlQuery();
    allItems = list.getItems(camlQuery);
    context.executeQueryAsync(Function.createDelegate(this, this.OnSuccess), Function.createDelegate(this, this.OnFailure));

c) You can always sort the items after retrival. You can refer to the answer of this question for an example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.