2014-03-27 57 views
0

我有我需要逐頁顯示的數據的SharePoint列表。必須要求是能夠跳過頁面並顯示總頁數(即1,2,3 ... 15)。 SharePoint允許這樣做嗎?SharePoint 2010中的富表列表分頁

到目前爲止我嘗試過: CAML:似乎不可能,因爲CAML查詢需要前一頁中的元素來顯示下一個元素。

REST:使用/_vti_bin/listdata.svc和LINQ查詢:

//VS2010 creates classes for all list items when adding reference to listdata.svc 
RootDataContext context = new RootDataContext(new Uri(Utils.ListServiceUrl)); 
context.Credentials = System.Net.CredentialCache.DefaultCredentials; 

//this works like a charm, I am able to filter items by category and page them 
//(category is a single lookup) 
var query = (DataServiceQuery<NewsItemsItem>)context.NewsItems. 
      Where(i => i.CategoryId == 2). 
      Skip(3). 
      Take(2); 

//however, if I need more advanced filtering (Tags is multilookup) I fail 
//(the code below won't work as this approach does not allow to make aggregation 
//queries inside other query) 
var query = (DataServiceQuery<NewsItemsItem>)context.NewsItems. 
      Where(i => i.Tags.Where(t => t.Id == 3).Count() > 0). 
      Skip(3). 
      Take(2); 

我將不勝感激,如果你能給我什麼建議。

+0

決定擺脫我的列表中的多查找列,並把一個簡單的字符串列,而不是(即#1#4 #6)。現在我可以在這裏使用REST方法。 – DizzyBlack

回答

1

http://msdn.microsoft.com/en-us/library/ff798478.aspx 用linq跳到sharepoint不能幫你。因爲sharepoint沒有「跳過N個值」的工具。

檢查這篇文章。如果您按列排序並希望按照該命令在caml中對此列表進行分頁,那麼它們將非常有用。在SharePoint

http://blogs.msdn.com/b/dbadki/archive/2008/10/08/caml-query-execution-using-pagination-for-custom-columns.aspx

http://blogs.msdn.com/b/colbyafrica/archive/2009/02/19/learning-sharepoint-part-vi-list-pagination.aspx

反正列表分頁是安靜的可怕(我想不僅是我)。因爲我只能像「上一個 - 下一個」分頁而不是「1 2 3 4 5 ....」頁面

+0

感謝您的回覆。無論如何,我決定使用Linq到SharePoint,因爲沒有可接受的方式來使用CAML組織「1 2 3」風格的控件。我遇到的一個問題是在多查詢列上查詢,你不能這樣做,所以我最終改變了列表結構。 – DizzyBlack