0

I'm not sure how to use the GroupBy clause when querying a list. The SPListItemCollection or datatable looks exactly the same regardless of the groupby clause.

SPQuery query = new SPQuery();
query.Query = "<GroupBy><FieldRef Name=\"Area\"/></GroupBy>";

DataTable result = list.GetItems(query).GetDataTable();

// result.Rows.Count = Same as ungrouped query 

Is GroupBy only supported by Lists.asmx webservice?

Found a reference on MS Social which suggests it's not supported on the SPSiteDataQuery object http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/ab8df6f5-35a0-401e-88cb-3eb31362bf0c/

Edward Wilde
  • 25,967
  • 8
  • 55
  • 64

1 Answers1

3

I believe that clause is more related to how the grouping will be displayed in the UI. As far as the data returned goes, you might/should get some sorting but that's about it.

Regarding the UI, there is the GroupLimit element which limits how many groups are returned. There is also the Collapse element which has no meaning when used with SPQuery.

How were you hoping the data would be different?

Alex Angas
  • 59,219
  • 41
  • 137
  • 210
  • It looks you're right, I was naively hoping that the dataset might have a column indicating the grouped value, or there would be a property on the listitem collection that would return a hierarchical view of the data to support the grouping structure. – Edward Wilde Jul 01 '09 at 15:26
  • Oh! No way, SharePoint's not that helpful I'm afraid! – Alex Angas Jul 01 '09 at 15:35