1、SharePoint的列表进行2级以上的分组的方法SharePoint: Group By on more than 2 columns in a view (SP 2010) This is an update of an article written for SharePoint 2007. Many of the steps are the same in both 2007 and 2010, but both the SharePoint Designer steps and the default web part used for views have changed.Grou
2、p By on more than 2 columns in a view In my SharePoint classes I have often been of asked how to group on more than two levels in a view. I have always given the quick answer of use SharePoint Designer! But, some of you have asked How?. You may be sorry you asked but here goes Goals: Create a view w
3、ith nested groups deeper than just 2 levels Put the counts and totals at the bottom of each section. Do the above with no custom web parts, custom XSLT or anything that has to be deployed to the server. Sample:Secrets and Tricks needed: It cant be done out of the box in the browser SharePoint Design
4、er is needed to make the edits You need to convert the view web part to a SharePoint Designer Data Form Web Part You need a Sort and Group secret You need to fix the footer rows You need to manually add your totals, averages, counts etc. Warning!SharePoint 2010 does not consider a page with a Data F
5、rom Web Part to be a “view”. It only believes that a page is a “view” when it has an “Xslt List View Web Part”. In 2007 we could create a new view, edit it in SharePoint Designer as much as we wanted, and it was still a view. In 2010, SharePoint will not recognize a page without a XsltListViewWebPar
6、t as a view.So before you start If you just need a page with your list nicely grouped, it may be best just to create a web part page and store it in a library. Then add the Data Form Web Part using the steps below. If you want the page to be treated as a view, leave the XsltListViewWebPart on the pa
7、ge, but make it hidden. Then add the Data Form Web Part below the existing web using the steps below. o In SP 2010, a view page with an added web part introduces a bug or two. The ribbon will not be displayed. The view dropdown in the page title area will be missing the dropdown to select another vi
8、ew. My Example: I have a simple list (actually imported from Excel) with these columns: ID1, Bike, BikeType, BikeSize, BikeColor and Retail (price). I want to group this on BikeType, BikeSize, BikeColor and count the items and sum or average the price in each group. Create a new Standard View from t
9、he lists view menu. Dont bother with any options as we are just going to delete the default list web part. Or just create an empty web part page. (see “Warning” above) The “before” just a standard view with selected columns: If using an existing view page: Open your site with SharePoint Designer and
10、 click the Lists and Libraries node in the Site Objects pane Click your list (“Bikes” in my example) Click your view you created earlier (“Grouped” in my example) Otherwise create a new web part page in a library Notes (background only, you can skip this): o The view is now being displayed using a X
11、sltListViewWebPart (It was a ListViewWebPart in SP 2007) and can only be customized with the same options as found using a browser (Modify View) o The XsltListViewWebPart has the same grouping limitations and the ListViewWebPart (2 levels of grouping) o For more info on what has changed from the 200
12、7 ListViewWebPart and the XsltListViewWebPart see and o SharePoint Designer 2010 has two web parts for lists: XsltListViewWebPart - this is the web part used when you create a new View DataFormWebPart created from SharePoint Designer using Insert, Empty Data View o SPD 2010 adds a bit of confusion w
13、hen trying to add a “Data View” When you click Insert, (pick an existing list) SPD inserts an XsltListViewWebPart When you click Insert, Empty Data View SPD inserts a DataFormWebPart If starting with an existing view, delete or hide the existing web part. o Delete: In the Design window click in the
14、web part, click the WebPartPages:XsltListViewWebPart tab, press the Delete key or in the Code window select the entire WebPartPages:XsltListViewWebPart tag (including the start and end tags) and delete the code o Hide: In the Design window click in the web part. In the Ribbon in the List View Tools
15、section click the Web Part tab and then click Properties. In the Layouts section of properties click Hidden Insert an Empty Data View Web part o Click the Insert Ribbon tab and click the Data View button o Click Empty Data View o In the new web part click “Click here to select a data source” o Click
16、 your list and click OK (this will open the Data Source Details Pane) o Select the columns you want in your list (click a field, then Shift-click each additional field) o Click the “Insert Selected Fields as” button and click “Multiple Item View” Note: If you followed the earlier article for SharePo
17、int 2007, the rest of the steps are pretty much the same.Note: the view is now being displayed using a DataFormWebPart and: is no longer a “View” and can not longer be modified from the browser can be customized from SharePoint Designer, from the browser you can only rename the view, from the browse
18、r you can also use Site Actions, Edit Page, Modify Shared Web Part to hand edit the XSLT, ;-) going forward, columns added to the list will not be automatically added to the DataFormWebPart. You will need to use SharePoint Designer to manually add the columns to the “view. Save! At this point you ma
19、y want to click Save and review the results so far in a browser. Review the formatting and note the things you need to change. Edit the Data View Web Part Click the web part and note that you now have Data View Tools section in the SharePoint Designer ribbon. Click “Sort and Group” Remove any sort f
20、ields that may already be in the Sort Order column Add your top most group: o Click the field (BikeType) and o Click Add o Click “Show group header” o Click “Collapse group by default” (optional) o Click “Show group footer” (if you want counts and totals) Add your second group by clicking the field
21、(Example: Size) and clicking Add. If you stop here you will have groups, but all of your counts and totals will be wrong! We need to create both the text to display for the group and a hierarchy for the grouping. At the second level of our grouping we need to group on the combination of both columns
22、, “Bike Type” plus “Size” Click “Edit Sort Expression” o At a minimum you will need to concatenate the current grouping column with the previous grouping columns, and while you are at it you can add some “pretty” formatting: o Enter: concat(Bike_x0020_Type, - , Size) (Watch the capitalization! Use t
23、he exact name the Intelisense offers spaces are “coded” so “Bike Type” is “Bike_x0020_Type”.) o Note the preview at the bottom of the dialog box o Click OK o Click Show group header o Click Collapse group (optional) o Click Show group footer (if you want counts and totals) For the third and followin
24、g groups - repeat the step above with Sort Expressions similar to: concat(Bike_x0020_Type, - , Size, - , Bike_x0020_Color) More columns? In each new group include all of the fields from the previous groups along with any separators you like: concat(group1field, group2field, group3field, group4field,
25、 group5field, etc) or concat(group1field, - , group2field, - , group3field, - , group4field, - , group5field, etc) If you could see the full width of these you would see: Before clicking OK to leave this dialog box, check the order of the groups. They have probably gotten changed. (bug?) Make sure t
26、hey are in order something like: BikeType concat(Bike_x0020_Type, - , Size) concat(Bike_x0020_Type, - , Size, - , Bike_x0020_Color) Recheck each of the sort levels to see if these are still checked: o Click Show group header o Click Collapse group (optional) o Click Show group footer (if you want co
27、unts and totals) Optionally add one more column just to sort the data within the last group. Do not turn on the group header or group footer options for this sort-only field. Click OK to close the Sort and Group dialog box. You will probably want to change the Paging options as they default to 10 it
28、ems. Click the Paging button in the Ribbon (Data View Tools group, Option tab) Tip: If you have a lot of data in the list SharePoint Designer can get really slow. There are two things you could do here, set paging to a small number (not so good for testing multi-level grouping) or from the Common Co
29、ntrol Tasks select Show With Sample Data. If you want grand totals you will also need to click Data View Properties and check Show View Footer. Save! At this point you may want to click Save and review the results so far in a browser. You should now have all of your groups. Click the + to expand a s
30、ection. Now is a good time to clean up the formatting such as the gray background and odd row height in the group header and footer rows. (Right-click in the row in Design view and select Cell Properties. (click for bigger view) Your grouping work is now done. The following steps are only needed if
31、you want to add totals, counts, averages, etc. Now for totals! These steps describe adding totals to the footer rows, but also apply to modifying header (top of each group) rows. The Data View sets up the header and footer rows as a single cell with a column span of 99! To display totals in the same columns and the data you will need to fix these rows. You will need to fix each of the group footer rows plus the view footer row. In the
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1