简体   繁体   中英

Paging in SharePoint with SPSiteDataQuery

I'm attempting to write a WebPart for SharePoint that will display a list of the most recent uploads and modifications to the Site (including all Document Lists)

To that end I have created an SPGridView and I am using an SPSiteDataQuery to populate that with my (customisable) selected Lists. I'm aware that SPQuery has the ListItemCollectionPosition, but as far as I know this will not work for multiple lists, and doing one at a time ruins sorting/paging.

This is a snippet of what I have:

Dim query As New SPQuery()
Dim lists As String = "<Lists ServerTemplate='101'>"
For Each li As Guid In SelectedLists ' Personalisable Property
    lists &= "<List ID='" & li.ToString & "' />"
Next
lists &= "</Lists>"

query.Lists = lists
query.RowLimit = 30 ' This will be the page size and is temporarily hardcoded

' These Id's are all SPBuildInFieldId's converted ToString
query.ViewFields = "<FieldRef ID'" & _filenameId & "' />" &
   "<FieldRef ID='" & _modifiedId & "' />" &
   "<FieldRef ID='" & _modifiedById & "' />" &
   "<FieldRef ID='" & _versionId & "' />" &
   "<FieldRef ID='" & _checkedOutToId & "' />" &
   "<FieldRef ID='" & _fileSizeId & "' />" &
   "<FieldRef ID='" & _createdId & "' />" &
   "<FieldRef ID='" & _createdById & "' />"

query.Webs = "<Webs Scope='Recursive' />"
query.Query = "<OrderBy><FieldRef ID='" & _modifiedId & "' Ascending='FALSE' /></OrderBy>"

Dim temp as DataTable = objWeb.GetSiteData(query)
For Each row As DataRow In temp.Rows
    Dim aRow = dtTable.Rows.Add()

    ' Get List Information
    Dim listId As Guid = New Guid(row.Item("ListId").ToString)
    Dim thisList As SPList = objWeb.Lists(listId)

    Dim fileName As String = row.Item(_filenameId).ToString
    aRow.Item("DocIcon") = "/_layouts/15/images/" & Utilities.SPUtility.MapToIcon(objWeb, fileName, "")
    aRow.Item("FileName") =  fileName
    aRow.Item("FileLink") = objWeb.Url & "/" & thisList.Title & "/" & fileName
    aRow.Item("ListName") = thisList.Title
    aRow.Item("ListLink") = objWeb.Url & "/" & thisList.Title
    aRow.Item("Modified") = row.Item(_modifiedId).ToString
    aRow.Item("ModifiedBy") = New SPFieldLookupValue(row.Item(_modifiedById).ToString).LookupValue
    aRow.Item("Version") = row.Item(_versionId).ToString
    aRow.Item("CheckedOutTo") = New SPFieldLookupValue(row.Item(_checkedOutId).ToString).LookupValue
    aRow.Item("FileSize") = row.Item(_fileSizeId).ToString
    aRow.Item("Created") = row.Item(_createdId).ToString
    aRow.Item("Author") = New SPFieldLookupValue(row.Item(_createdById).ToString).LookupValue
Next

This DataTable is set to the source of my SPGridView, and that allows paging (I am currently using an SPGridViewPager), but it will always return the full collection of documents from the query, which is going to cause some overhead once there are a lot of documents.

What I'd like is to be able to paginate in the query itself so that it only returns correct documents for the current page (~30 at a time), but I'm hitting a wall trying to achieve this.

Is there a solution I'm missing that will allow me to both query a predetermined set of lists in modified order, and also paginate at query time?

Thanks in advance and apologies for any bad wording/formatting, this is my first question on this site.

There is a workaround for this case, while it may not 'best choice' if you have huge data volume.

"Imagine If we want to display 25 records in a page & the user wants to navigate to page no 2.

uint recordsPerPage = 25;

uint pageNumber = 2;

So the rowLimit property of our query should be 25 * 2 = 50."

https://nivas07.wordpress.com/2010/06/15/paging-using-spsitedataquery/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM