Introduction

I have explained in the previous article how to work with SharePoint list items, basically performing CRUD operations, using the combination of REST API and jQuery Ajax. The REST URI ends with any OData query operators to specify selecting, sorting, or filtering.Let’s see other parameters and options which can be used with REST services. We will start from basic REST url and will take Selecting, filtering, sorting and pagination options one by one.

The main agenda of this Article is to understand how you can take selecting, filtering, sorting and pagination options one by one.

infolist

Scenarios

There can be scenarios where you want to perform additional operations on data returned by REST API like selecting, filtering, sorting and paginationfields only etc. For such operations while forming Url to Get data, we have to add some parameters as described below:

Ascending Order

  1. /_api/web/lists/getbytitle('infolist')/items?$select=ID,Title,Employee,company&$orderby= Employee asc
Descending Order
  1. /_api/web/lists/getbytitle('infolist')/items?$select=ID,Title,Employee,company&$orderby= Employee desc

Note

The $skipoperator does not work in SharePoint 2013 on list items.it works only on Lists.

See below example

/_api/web/lists? Orderby Title desc&$skip

$expand

This is very useful when dealing with person or lookup fields where only Id is returned. Using this we can get corresponding value based on Id.

See below example

Lookup Field:Say there is City column in County list which is a lookup to Title column in Info List.

  1. /_api/web/lists/getbytitle('infolist')/items?$select=ID,Title,Employee,company,city/Id&$expand=city/Id
People Field

Let’s say a list has custom field: Author, it will return ‘AuthorId’ in response. What is the proper way to deal with people field? You need to use ‘$expand’ parameter to expand the field.

Following REST URL gives your idea how to use $expand.
  1. /_api/web/lists/getbytitle('infolist')/items?$select=Author/Title&$expand=Author/Id
Reference
Read more articles on SharePoint,