Paging and sorting by the underlying provider

By default, data sorting is performed by the service broker layer. If the back-end system will handle paging and sorting, it is possible to override the default behavior and page/sort data before the data is returned to the custom service broker - this is known as handled paging and sorting. When handled paging and sorting is implemented, the built-in functionality for paging and sorting on the service broker layer will be bypassed; data will be sorted and paged by the underlying provider before being passed to the service broker, and only data within the required page will be passed to the service broker.

The advantage of handled paging and sorting is that performance is increased, because only the required data is passed back to the service broker and there is no extra step of sorting at the service broker level.

You can instruct your service broker that the provider will implement handled paging and sorting, by setting the HandledPaging property found in SourceCode.SmartObjects.Services.ServiceSDK.ServiceAssemblyBase for your class to True.

The HandledPaging property must be set to True, and then you can read values for the following properties found in SourceCode.SmartObjects.Services.ServiceSDK.Objects.ServicePackage during method execution to query paging and sorting details, and pass these down to the provider.

  • OrderBy : A <string,string> dictionary containing the service instance column and the sorting order, as specified by the client.
  • PageNumber: the current page.
  • PageSize: The number of records in the page.
  • StartRecord: The first record in the page.
  • MaxRecord: Maximum number of records in the page.
Copy

HandledPaging properties

int maxRecords = this.ServicePackage.MaxRecords;
int pageNumber = this.ServicePackage.PageNumber;
int pageSize = this.ServicePackage.PageSize;

Considerations

If the RuntimeListViewRowCount SmartObject performance setting is set to true in the K2 Runtime web.config file, you must add the following code to correctly handle paging.

Copy

Consideration

int startRecord = (pageSize * (pageNumber - 1));
serviceBase.TotalRecordCount = numberOfRecords;