简体   繁体   English

使用SPSiteDataQuery在SharePoint中分页

[英]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) 我试图编写一个用于SharePoint的WebPart,以显示该网站的最新上传和修改列表(包括所有文档列表)

To that end I have created an SPGridView and I am using an SPSiteDataQuery to populate that with my (customisable) selected Lists. 为此,我创建了一个SPGridView,并使用SPSiteDataQuery用(可定制的)选定列表填充该列表。 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. 我知道SPQuery具有ListItemCollectionPosition,但是据我所知,它不适用于多个列表,并且一次执行一次会破坏排序/分页。

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. 此DataTable设置为SPGridView的源,并且允许分页(我目前正在使用SPGridViewPager),但是它将始终从查询中返回文档的完整集合,一旦有很多,这将导致一些开销文件。

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. 我想要的是能够在查询本身中进行分页,以便它仅返回当前页面的正确文档(一次约30个),但是我遇到了麻烦,试图做到这一点。

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. “想象一下,如果我们要在一个页面中显示25条记录,而用户希望导航到第2页。

uint recordsPerPage = 25; uint recordsPerPage = 25;

uint pageNumber = 2; uint pageNumber = 2;

So the rowLimit property of our query should be 25 * 2 = 50." 因此,我们查询的rowLimit属性应为25 * 2 =50。”

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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