There are some rare scenarios where you want group-by for more than 2 columns in list view of SharePoint list. But by default SharePoint doesn’t provide this function. OOB you can do a group-by for at-most 2 columns.So how we can go for it??
Here’s a simple way using SharePoint Designer along with some changes & additions. No customization / no code required. Here we go.
1) Create a view for your list without any filtering or sorting.
2) Now open SharePoint designer and open the view you have created.
3) Right-click on the default ListViewWebpart that displays the content of list & and select Convert to XSLT Data View.
4) At this point the data will be displayed using a DataViewWebpart and from now on
- You cannot edit any of the details of the view from the browser except its name.
- Can be edited only from designer.
- You can also use Site Actions, Edit Page, Modify Shared Web Part to hand edit the XSLT from the browser.
- New columns added to the list hereafter will not appear in the view.
5) Now its time to make group by for the required columns. (In my case the three columns that has to be grouped ion order are IDU, Location & Title respectively).
6) Right-click on the DataViewWebpart and select Show Common Control Tasks and then select Sort & Group option that appear on the Common Data View Tasks pop-up menu.
- Remove any sorted fields already available (ID column will be the one).
- Now select & add all the three Group By columns in order to the Sort Order box.
- Click “Show group header”.
- Click “Show group footer” (This displays the count with totals).
8 ) Now click OK and if you save the page and check the page in browser you will be having group by but the columns will have wrong count.
9) This is due to the sort expression for the columns we have added and hence a small change is required.
10) So do the step 6 again, Click on the Edit Sort Expression button for the first column you have added (In my case its IDU).
11) In the Edit the XPath Expression text box make sure it shows as @IDU.
12) Now at a minimum you will need to concatenate the current grouping column with the previous grouping columns.
13) So for the second column I am changing the sort expression to concat(@IDU,’-',@Location) & for the third column to concat(@IDU,’-',@Location,’-',@Title.
14) Now verify once the sort columns are in the same order (Most probably it will change).
15) That’s it. Save the page and view the page in browser.
16) Now the view will be with default gray back ground.
17) You can change the color by selecting the td’s in the code view and choosing appropriate color.