Solved: Can't Group By Choice Column in SharePoint List View - SharePoint Development & Administration + InfoPath

Friday, September 11, 2009

Solved: Can't Group By Choice Column in SharePoint List View

By Default, items in a SharePoint list can't be grouped by a Choice field if it allows multiple selections (checkbox).

To be able to group by the value of a Choice field in a SharePoint list or library which allows multiple selections, you need to ensure that the Choice field/column is set as Radio Buttons or a Drop Down Menu. Both of these options only allow a single selection of the available choices, which is required to allow grouping by the column/field using Standard SharePoint List views.

To group by a Choice field which allows multiple selections (checkboxes), convert the Web Part to a Data View using SharePoint Designer, then apply grouping doing the following:

1. From the "Common Data View Tasks" menu for the Data View Web Part, select "Sort and Group:" from the options to open the Sort and Group Dialog, add any field into the Sort Order section to activate the "Edit Sort Expression..." button. Click the "Edit Sort Expression..." button to open the Advanced Sort Dialog.

2. From the list of fields, add the Choice field, and make sure that the field reference is the only value in the "Edit the XPath expression" input.
The field reference should begin with an @ symbol followed by the internal name
of the SharePoint column/field (example: @Location). The value from the
selected column will display in the Preview box if items in the list/library
match the specified criteria, which in this case is a simple column/field value
(no conditions or calculations required).

3. Press OK on to close the Advanced Sort Dialog. Select the Choice Field from the list of fields in the "Sort Order:" box, then select "Show Group Header" under Group Properties. This will result in items being grouped by the value in the choice field which allows multiple selections.
Share this article:
Stumble This Delicious
Delicious
submit to reddit
Facebook
MySpace
MySpace

13 comments:

tfiema said...

When I use a Data View for a doc lib that has a multi select column, that column's data is not shown in the Data View. It does not matter if the filed has one value selected or multiple. It's like the Data View doesn't get the data for that column. Is there something weird going on, in the data. As far as I can tell multiple values are stored like this: ;#val1;#val2;#vla2;#
And the Data View's XSLT is be default taking care of the parsing between ;# . So I assume this is supposed to work, but it doesn't.

Daniel said...

Hi tfiema,

Just to clarify, has the column has been added to the data view, but not showing the data, or is the column not available at all from the data source details task pane for the document library?

Is the column a Lookup which allows multiple selections, or is it a Choice field with check boxes?

If the columns are there just empty, does SharePoint Designer, or the browser display the data, once you have saved the page? You may need to refresh the data source to update the items that are displayed in the Design view of SPD.

Also, if the column is a lookup to another list or library on SharePoint, no data will display if the item referred to by the lookup has been removed from the other list/library.

Thanks

Daniel

minstrel said...

Thanks for this post, it helped quite a bit.

Just a question however;
When changing from the list view to the data view, the column filters seem to disappear. Is there a way to get those back?

Thanks.

Daniel said...

You can add the filter criteria to the Data view again using the Filter dialog from the "Common Data View Tasks" menu for the Data View Web Part (right click).

Create a separate entry/row in the filter criteria table for each of the required conditions. The order of the conditions is important. Grouping certain criteria together may be required if you are getting unexpected results (example below displays items with a specific value in a custom field/column with a due date in the next 2 weeks).


[ group1
CustomField = "val1"
Due Date >= [today]
]

AND

[ group2
CustomField = "val1"
Due Date < [today]-14
]

Using the standard features Filter dialog provided by SharePoint Designer for Data view Web Parts in most cases provides much more control over filter criteria than the standard browser functionality provided by SharePoint.

Daniel

KT said...

Thanks for the helpful post. I was wondering if it is possible to group such that each item is grouped separately, instead of each combinations of items grouped.

LIST
file 1 keyword 1;keyword 2;keyword 3
file 2 keyword 1
file 3 keyword 1;keyword 3

DVWP - desired
+keyword 1
- file 1
- file 2
- file 3
+keyword 2
- file 1
+keyword 3
- file 1
- file 3

DVWP - default display when group according to look-up column with multi-select .

+keyword 1
- file 2
+keyword 1;keyword 3
- file 3
+keyword 1;keyword 2;keyword 3
- file 1

Thanks.

elizas said...

Good one.i want to add to this.n Sharepoint, columns like Choice Field are often used to hold multiple choice options which are then displayed as values of DropdownList / RadioButtonList / CheckboxList. While developing Custom Webparts for add/edit form (related to any List having the Choice Fields) in VS 2005, there is always a need to fetch these choice options and bind them to the corresponding ASP.Net Server Control.

http://www.mindfiresolutions.com/lp/sharepoint-development.htm

Asaf said...

Did anyone find a solution for how to group the items separately?

Robin Majumdar said...

Thanks for sharing - this is pretty helpful... I too am researching a grouping method for multiple choice that shows each item/file under each individual group selection as shown by KT above.

I.E. the DVWP - desired style...

Stefanie said...

I don't have 'Edit Sort Expression' as an option

What's going on?

Stefanie said...

Ahhh convert to XSLT view

Daniel said...

Hi Asaf, the following article which allows grouping on a column with multiple values, but uses a lookup field rather than a multiple choice field. May be of some assistance.

SharePoint – Group By a Column with Multiple Values

firozaghosh said...

Hi this was a good walk around, trying to find a way to group items separetly by each choice.

Te Papa said...

Thanks heaps for your article, it worked like a charm for me :)
Florence

Post a Comment