Answered Collapse attribute in GroupBy element of webpart caml query

  • Thursday, April 26, 2012 9:42 AM
     
      Has Code

    Hi,

    I have a problem with collapse of groups in sharepoint document library. If I don't use collapse attribute it works properly:

    <GroupBy>
         <FieldRef Name="Title" />
    </GroupBy>

    But if I try to use that attribute like this:

    <GroupBy collapse="false">
        <FieldRef Name="Title" />
    </GroupBy>

    I see that each group contains all documents independently of its Title value.

    Is it bug and how to resolve it?


    • Edited by GydroCasper Thursday, April 26, 2012 9:52 AM
    •  

All Replies

  • Thursday, April 26, 2012 10:25 AM
     
     

    Hi GydroCasper,

    Please try to modify your code using "Collapse" instead of "collapse" and "FALSE" instead of "false".

    :)

    Regards,

    Ludovic Caffin

  • Thursday, April 26, 2012 12:04 PM
     
      Has Code

    Hi, Ludovic!

    It didn't help. It is still a problem.

    That is my code:
                    XmlNode groupByNode = queryNode.SelectSingleNode("GroupBy");
                    if (groupByNode != null) queryNode.RemoveChild(groupByNode);
                    XmlNode newGroupByNode = doc.CreateNode(XmlNodeType.Element, "GroupBy", String.Empty);
                    newGroupByNode.InnerXml = AddGroupByClause();
                    XmlAttribute collapseAttr = doc.CreateAttribute("Collapse");
                    collapseAttr.Value = "TRUE";
                    newGroupByNode.Attributes.Append(collapseAttr);
                    queryNode.AppendChild(newGroupByNode);
    
                    FilteredLibraryWebPart.ListViewXml = doc.OuterXml;

    • Edited by GydroCasper Thursday, April 26, 2012 12:05 PM
    •  
  • Thursday, April 26, 2012 12:34 PM
     
     

    I am going to try to reproduce this on my side:

    • What is the value of the "doc.OuterXml" property?
    • What kind of web part is "FilteredLibraryWebPart"? Is it a ListViewWebPart?

    Thanks

  • Thursday, April 26, 2012 1:06 PM
     
      Has Code

    1.Value of doc.OuterXml is:

    "<View Name=\"{95283F37-E093-497A-90BF-06EA64298515}\" DefaultView=\"TRUE\" MobileView=\"TRUE\" Type=\"HTML\" DisplayName=\"Все документы\" Url=\"/Lotus/DocLib/Forms/AllItems.aspx\" Level=\"1\" BaseViewID=\"1\" ContentTypeID=\"0x\" ImageUrl=\"/_layouts/images/dlicon.png\"><Toolbar Type=\"Standard\" ShowAlways=\"TRUE\" /><XslLink Default=\"TRUE\">main.xsl</XslLink><RowLimit Paged=\"TRUE\">30</RowLimit><ViewFields><FieldRef Name=\"DocIcon\" /><FieldRef Name=\"LinkFilename\" /><FieldRef Name=\"Modified\" /><FieldRef Name=\"Editor\" /></ViewFields><ParameterBindings><ParameterBinding Name=\"NoAnnouncements\" Location=\"Resource(wss,noitemsinview_doclibrary)\" /><ParameterBinding Name=\"NoAnnouncementsHowTo\" Location=\"Resource(wss,noitemsinview_doclibrary_howto2)\" /></ParameterBindings><Query><OrderBy><FieldRef Name=\"FileLeafRef\" /></OrderBy><Where><And><Geq><FieldRef Name=\"_x0414__x0430__x0442__x0430__x0020__x043f__x0440__x0438__x043a__x0430__x0437__x0430_\" /><Value Type=\"DateTime\">1993-07-07T00:00:00</Value></Geq><Lt><FieldRef Name=\"_x0414__x0430__x0442__x0430__x0020__x043f__x0440__x0438__x043a__x0430__x0437__x0430_\" /><Value Type=\"DateTime\">2012-04-27T17:04:29</Value></Lt></And></Where>
    
    <GroupBy Collapse=\"TRUE\">
    <FieldRef Name=\"_x0422__x0435__x043c__x0430__x0442__x0438__x043a__x0430_\" /></GroupBy></Query></View>"

    2. Yes it is:

    public Microsoft.SharePoint.WebPartPages.ListViewWebPart FilteredLibraryWebPart

  • Thursday, April 26, 2012 1:40 PM
     
      Has Code

    In your first message you gave the following code :

    <GroupBy>
         <FieldRef Name="Title" />
    </GroupBy>

    But in your last message, we found :

    <GroupBy Collapse=\"TRUE\">
    <FieldRef Name=\"_x0422__x0435__x043c__x0430__x0442__x0438__x043a__x0430_\" />
    </GroupBy>

    the field name "_x0414__x0430__x0442__x0430__x0020__x043f__x0440__x0438__x043a__x0430__x0437__x0430_" seems strange.

    Is it the intended name value of one of the list fields you use? What kind of field is it?

  • Friday, April 27, 2012 2:57 PM
     
      Has Code

    The first message was so because it is easy to understand, but internal name was the same. Strange name is because column name was on russian. Now I recreate library with english names but problem is still happen. For now code is:

    <GroupBy Collapse=\"TRUE\">
    <FieldRef Name=\"Subject1\" />
    </GroupBy>

  • Tuesday, May 01, 2012 7:57 AM
     
      Has Code

    I can't test code today, but here is a tip to help you.

    1. On a SharePoint list, create a view with the user interface and which respect all the rules you try to specify by code. So you will set the "group by" setting with the correct "collapse" option.

    2. Then with code, get the SPList item corresponding to this list, and the SPView item corresponding to the view you just created.

    3. You will then be able to get the xml definition of this view with SPView.SchemaXml :

    SPList oList = oWebsite.Lists["List_Name"];
    SPView oView = oList.Views["View_Name"];
    string myView = oView.SchemaXml;
    4. Compare the xml definition you already tried with the one build by SharePoint.

  • Wednesday, May 02, 2012 9:58 AM
     
      Has Code

    I created view with grouping as you adviced. The difference from default view is grouping by Subject1 column. After that I deleted and recreated GroupBy node by scratch. In result I have that layout of library and it is working properly:

    <View Name=\"{5B7AEEC7-E35C-4601-BEB3-B05C2B9EC9EB}\" DefaultView=\"TRUE\" MobileView=\"TRUE\" Type=\"HTML\" DisplayName=\"Test\" Url=\"/Lotus/NormDocs/Forms/Test.aspx\" Level=\"1\" BaseViewID=\"1\" ContentTypeID=\"0x\" ImageUrl=\"/_layouts/images/dlicon.png\"><ViewFields><FieldRef Name=\"DocIcon\" /><FieldRef Name=\"LinkFilename\" /><FieldRef Name=\"Section\" /><FieldRef Name=\"Subject1\" /></ViewFields>
    
    <Query><Where><And><Geq><FieldRef Name=\"OrderDate\" /><Value Type=\"DateTime\">1993-07-07T00:00:00</Value></Geq><Lt><FieldRef Name=\"OrderDate\" /><Value Type=\"DateTime\">2012-05-03T13:43:19</Value></Lt></And></Where>
    
    <GroupBy Collapse=\"TRUE\"><FieldRef Name=\"Subject1\" /></GroupBy>
    
    </Query><Aggregations Value=\"Off\" /><Mobile MobileItemLimit=\"3\" MobileSimpleViewField=\"LinkFilename\" /><Toolbar Type=\"Standard\" /><XslLink Default=\"TRUE\">main.xsl</XslLink><RowLimit Paged=\"TRUE\">30</RowLimit><ParameterBindings><ParameterBinding Name=\"NoAnnouncements\" Location=\"Resource(wss,noitemsinview_doclibrary)\" /><ParameterBinding Name=\"NoAnnouncementsHowTo\" Location=\"Resource(wss,noitemsinview_doclibrary_howto2)\" /></ParameterBindings></View>

    But when I choose grouping column (it depends on dropdownlist value) it was error (fault representation):

    <View Name=\"{5B7AEEC7-E35C-4601-BEB3-B05C2B9EC9EB}\" DefaultView=\"TRUE\" MobileView=\"TRUE\" Type=\"HTML\" DisplayName=\"Test\" Url=\"/Lotus/NormDocs/Forms/Test.aspx\" Level=\"1\" BaseViewID=\"1\" ContentTypeID=\"0x\" ImageUrl=\"/_layouts/images/dlicon.png\"><ViewFields><FieldRef Name=\"DocIcon\" /><FieldRef Name=\"LinkFilename\" /><FieldRef Name=\"Section\" /><FieldRef Name=\"Subject1\" /></ViewFields>
    
    <Query><Where><And><Geq><FieldRef Name=\"OrderDate\" /><Value Type=\"DateTime\">1993-07-07T00:00:00</Value></Geq><Lt><FieldRef Name=\"OrderDate\" /><Value Type=\"DateTime\">2012-05-03T00:00:00</Value></Lt></And></Where>
    
    <GroupBy Collapse=\"TRUE\"><FieldRef Name=\"Section\" /></GroupBy>
    </Query><Aggregations Value=\"Off\" /><Mobile MobileItemLimit=\"3\" MobileSimpleViewField=\"LinkFilename\" /><Toolbar Type=\"Standard\" /><XslLink Default=\"TRUE\">main.xsl</XslLink><RowLimit Paged=\"TRUE\">30</RowLimit><ParameterBindings><ParameterBinding Name=\"NoAnnouncements\" Location=\"Resource(wss,noitemsinview_doclibrary)\" /><ParameterBinding Name=\"NoAnnouncementsHowTo\" Location=\"Resource(wss,noitemsinview_doclibrary_howto2)\" /></ParameterBindings></View>
    All column names on English, but cell items on Russian, but it is not a problem when I create view for grouping by this column names. Problem exists only when I change CAML query by scratch.


    • Edited by GydroCasper Wednesday, May 02, 2012 9:59 AM
    •  
  • Wednesday, May 02, 2012 4:07 PM
     
     

    I didn't well understood what you wrote.

    "I created view with grouping as you adviced."

    ok

    "The difference from default view is grouping by Subject1 column."

    We don't need the difference between the view you need and the default view.

    Because we are sure the CAML syntax generated by SharePoint is correct, we need the difference between the view you created with the user interface and the view you try to create by code.

    "After that I deleted and recreated GroupBy node by scratch. In result I have that layout of library and it is working properly"

    and then

    "But when I choose grouping column (it depends on dropdownlist value) it was error (fault representation):"

    I don't understand here what you are trying to explain. From the XML samples you gave, did you mean the "Group by" option works with "Subject1" column but not with "Section" column? if yes, what kind of column "Section" is?


  • Saturday, May 05, 2012 10:20 AM
     
      Has Code

    When I created View in web-interface of Sharepoint with grouping I have the next CAML code:

    <View Name=\"{CBE0F43B-B71D-4831-9A1F-60B1036818B2}\" DefaultView=\"TRUE\" MobileView=\"TRUE\" MobileDefaultView=\"TRUE\" Type=\"HTML\" DisplayName=\"Все документы\" Url=\"/Lotus/DocLib/Forms/AllItems.aspx\" Level=\"1\" BaseViewID=\"1\" ContentTypeID=\"0x\" ImageUrl=\"/_layouts/images/dlicon.png\"><ViewFields><FieldRef Name=\"DocIcon\"/><FieldRef Name=\"LinkFilename\"/><FieldRef Name=\"OrderDate\"/><FieldRef Name=\"Department1\"/><FieldRef Name=\"Acceptment\"/><FieldRef Name=\"OrderNumber\"/><FieldRef Name=\"CancelFlag\"/><FieldRef Name=\"Section\"/><FieldRef Name=\"Subject1\"/><FieldRef Name=\"DeveloperName\"/></ViewFields>
    
    <Query>
    	<GroupBy Collapse=\"TRUE\" GroupLimit=\"30\">
    		<FieldRef Name=\"Subject1\"/>
    	</GroupBy>
    	<OrderBy>
    		<FieldRef Name=\"FileLeafRef\"/>
    	</OrderBy>
    </Query>
    
    <Aggregations Value=\"Off\"/><RowLimit Paged=\"TRUE\">30</RowLimit><Mobile MobileItemLimit=\"3\" MobileSimpleViewField=\"LinkFilename\"/><XslLink Default=\"TRUE\">main.xsl</XslLink><Toolbar Type=\"Standard\"/><ParameterBindings><ParameterBinding Name=\"NoAnnouncements\" Location=\"Resource(wss,noitemsinview_doclibrary)\"/><ParameterBinding Name=\"NoAnnouncementsHowTo\" Location=\"Resource(wss,noitemsinview_doclibrary_howto2)\"/></ParameterBindings></View>

    And it works properly. But if I do the same by code:

    <View Name=\"{CBE0F43B-B71D-4831-9A1F-60B1036818B2}\" DefaultView=\"TRUE\" MobileView=\"TRUE\" MobileDefaultView=\"TRUE\" Type=\"HTML\" DisplayName=\"Все документы\" Url=\"/Lotus/DocLib/Forms/AllItems.aspx\" Level=\"1\" BaseViewID=\"1\" ContentTypeID=\"0x\" ImageUrl=\"/_layouts/images/dlicon.png\"><ViewFields><FieldRef Name=\"DocIcon\" /><FieldRef Name=\"LinkFilename\" /><FieldRef Name=\"OrderDate\" /><FieldRef Name=\"Department1\" /><FieldRef Name=\"Acceptment\" /><FieldRef Name=\"OrderNumber\" /><FieldRef Name=\"CancelFlag\" /><FieldRef Name=\"Section\" /><FieldRef Name=\"Subject1\" /><FieldRef Name=\"DeveloperName\" /></ViewFields>
    
    <Query>
    	<GroupBy Collapse=\"TRUE\" GroupLimit=\"30\">
    		<FieldRef Name=\"Subject1\" />
    	</GroupBy>
    	<OrderBy>
    		<FieldRef Name=\"FileLeafRef\" />
    	</OrderBy>
    </Query>
    
    <Aggregations Value=\"Off\" /><RowLimit Paged=\"TRUE\">30</RowLimit><Mobile MobileItemLimit=\"3\" MobileSimpleViewField=\"LinkFilename\" /><XslLink Default=\"TRUE\">main.xsl</XslLink><Toolbar Type=\"Standard\" /><ParameterBindings><ParameterBinding Name=\"NoAnnouncements\" Location=\"Resource(wss,noitemsinview_doclibrary)\" /><ParameterBinding Name=\"NoAnnouncementsHowTo\" Location=\"Resource(wss,noitemsinview_doclibrary_howto2)\" /></ParameterBindings></View>
    I see that in each group are all documents and it is not depending of which Subject1 column value its has. It is very strange, I tried even copy .ListViewXml from correct code, but I had two different results with two equal CAML code... Do you have ideas about that bug?



    • Edited by GydroCasper Saturday, May 05, 2012 10:46 AM
    • Edited by GydroCasper Saturday, May 05, 2012 10:47 AM
    •  
  • Wednesday, May 09, 2012 9:39 AM
     
     Answered

    You now are sure we have the correct CAML query as you picked up the one generated by SharePoint.

    If you specify this query by code, the displaying is not coherent.

    I have two ideas:

    Check the query generated by code

    Specify the correct CAML query by code.

    Check the "oView.SchemaXml;" of the generated view.

    There could be differences between the query you specified and the one generated. What are these differences?

    Check if this problem could be caused by the XML encoding

    There is maybe a problem with the XML encoding of the field names.

    You could try to encode the field names with : XmlConvert.EncodeName.

    More information: http://msdn.microsoft.com/en-us/library/system.xml.xmlconvert.encodename.aspx

    • Proposed As Answer by Ludovic Caffin Monday, May 14, 2012 12:35 PM
    • Unproposed As Answer by GydroCasper Thursday, July 19, 2012 12:20 PM
    • Marked As Answer by GydroCasper Thursday, July 19, 2012 12:21 PM
    •