SharePoint 2010 External List Paging – Server Side

By

When you are using an External List to display data through the Business Connectivity Services from your External Data Source you do not want to be bringing back thousands of records of data. This is a bad setup in terms of performance hit on the hardware and also experience of the end user as they may only want 20 records displayed at a time, so no need to bring them all over. What we need to do is allow an External List to page through the data, executing a query on the External Data Source so only the current records required for what the user wants to review are returned. This is known as server side paging.

In this walkthrough we’ll show you how to configure a BCS finder method to provide custom paging. We will use BCS Meta Man to create an external content type and configure the finder method to provide custom paging ability.

1) Launch Visual Studio 2010 and create a new empty SharePoint project. Add a BCS Meta Man project item from the Lightning Tools project items group. Connect to your database(we have used AdventureWorks2000 database in this walkthrough) by using the main menu BCS Meta Man –> BCS Meta Man Data Explorer and connect to your database you wish to use. It should looked like this

BCS Meta Man connected to data source

[Please click the images for a larger view]

2) Drag and drop a table from the data source explorer on to design surface. Choose .Net Assembly as a model type.

Use .NET Assembly as model type External Content Type created on design surface

3) Now we need to create two filters. The first one will keep information about the records count per page, and the second one will keep information about the start row. Using these values we can support custom paging. Right click on the external content type, and choose “Manage Entity”

Manage the External Content Type

4) Navigate to the Methods tab and select the finder method. Click on the Add Filter button. We will create a filter for records count per page. Set 30 as a default value.

Records Count Filter

5) Create another filter for first row number, using the same way that is described in step 4. We need to use a nullable type column for that filter because later when we will try to retrieve first row number information from the external list, we will see that value is null for the first page, so to avoid exceptions we need to create this filter on a nullabe type column. We have used SalesPersonId column of the Customer table. Set 1 as a default value.

Setup row number filter

6) Now we need to make a small modification to the C# code that is generated for our Finder method. To support custom paging, each time we need to retrieve (N*C+1) records, where N is the page number, C is records count per page, and we need to add 1 extra row so that SharePoint knows it can page. So for example if you want first 30 records and paging enabled, you need to retrieve 31 records. When the Next/Page button is clicked, it should retrieve 61 records but the start row number set to 31. We need to modify the finder method code, and it should looked like this.

Modify your Finder method

7) Now you can press F5 to deploy the solution, go to SharePoint site and create a new external list based on the deployed external content type. When list is created, go and modify the view.

Modify the External List view

8) On the Edit List View page scroll down and you’ll find the place to set values for the filters that we created in step 4 and 5. You need to set {dvt_firstrow} as the value for RowNumber filter. {dvt_firstrow} is an argument value that is being posted by an external list when you click on next/previous buttons. It holds the value of the first row number of an external list. So if you click on next button and it navigates to the second page which contains the second 30 records, {dvt_firstrow} will be equal to 31. Here is the screenshot of that post back.

{dvt_firstrow} value in External List

9) For the RecordsCount filter value, you should set this to be the same value that is specified in your external list’s Items Limit section. Using this value it should retrieve the next bunch of records. In Edit View, if you go to Items Limit section you’ll see 30 as the default value. Lets change it to 10.

Set the External List Limit Filter

10) Finally here is the screenshot of the values of our defined BCS filters.

BCS filters setup for our External List

So, when we have dvt_firstrow and RecordsCount values we can calculate the value of N = dvt_firstrow/RecordsCount+1. For example, if our page contains 10 records, and dvt_firstrow = 21(which means that it should show records from 21 to 30), then N=21/10+1 which is equal to 3. So, N*C+1 = 3*10+1=31. So it will retrieve 31 records and external list will show records from 21 to 30.

Using this technique we can provide custom paging of our external content list .

External List -viewing the first page of data External List - paging buttons displayed More paging!