2

I have a Document Library with a custom "choice" column. I use that column to "Group By" in my views. The column sorts alphabetically, but instead I would like it to sort in a custom order. Is there a way to do this? I'm using SharePoint 2010. The obvious work around is to add an entry number to the choice list (i.e. 1. Choice X, 2. Choice B, etc). I'm looking to see if there is a way to to this without the workaround.

Thanks

5 Answers 5

3

Use a calculated column and the Contains formula.

  1. Create a calculated column.

  2. Enter the Contains formula. Below is a template to get you started. Replace [ColumnName] with the name of your column and Text with the choice value from the column. Match the choice entry with the number you would like the entry be associated with for sorting.

     =IF([ColumnName]="TEXT",1,IF([ColumnName]="TEXT",2,IF([ColumnName]="TEXT",3,IF([ColumnName]="TEXT",4,IF([ColumnName]="TEXT",5,IF([ColumnName]="TEXT",6,IF([ColumnName]="TEXT",7,IF([ColumnName]="TEXT",8,IF([ColumnName]="TEXT",9)))))))))
    
  3. Create a view and sort by the new calculated column.

For step-by-step instructions with screenshots view my post on sorting items in a list using the Contains formula. Post: http://jennyssharepointtips.wordpress.com/2014/11/21/create-a-custom-sort-using-the-contains-formula-in-a-calculated-column/

1

I'm afraid your workaround is the only option you have

1
  1. Create a single line of text column named Position. In this column, you will enter in the position you want for that list item's group in this column. 1 for all items in the first group in the list, 2 for the second, etc.
  2. Create a calculated column that you will use to group your list, e.g. Calculated Choice
  3. In the formula section, enter the following: =REPT(" ",(20-Position))&[Choice]. I had a total number of 20 choices, hence the 20. This will repeat a space 19 times and then concatenate Choice on the end for the group with Position 1.
  4. In your view, group by the Calculated Choice column you created. Then, SharePoint will sort this automatically, with values that have more spaces appearing higher on the list.

Solution adapted from Christophe's Path to SharePoint blog. This saved my butt!

0
0

Ok. Here is a way to get exactly what you want.

  1. Create a calculated column that returns type number.
  2. Record the background color of your view page - usually this will be white.
  3. For the calculated column, use:

=IF([*Group Column Name*]="*Group Heading of First Group*","<span style='color:*background color of view*'>1</span>*Group Heading of First Group*",IF([*Group Column Name*]="*Group Heading of Second Group*","<span style='color:*background color of view*'>2</span>*Group Heading of Second Group*",*","<span style='color:*background color of view*'>3</span>*Group Heading of Third Group*"))

  1. Group by your calculated column.

The example above contains 3 groups. The 'number' return type of a calculated column will be read as html and not escapced. When you add a span with the same background color it will not show up but it will be read for Alpha order.

Here is an example of the calculated formula:

=IF([Environment Type]="Production","<span style='color:white'>1</span>Production",IF([Environment Type]="Test","<span style='color:white'>2</span>Test","<span style='color:white'>3</span>Development"))

0

My attempts to use the Calculated Formulae approach kept failing, but then the following very simple solution popped into my head... and it works!! :) So here you go - enjoy :)

First step is to create two columns in your document library:

  • GROUP_HEADING will contain the actual Group Heading names you want to apply to your document groupings.
  • GROUP_SORT will contain a number (01, 02, 03, etc). These numbers will indicate the order in which you want your groupings to appear in your document library.

So basically, if you want your items to appear in a certain order that is NOT alphabetical - e.g. HeadingC, HeadingD, Heading B, Heading A - then you would allocate the GROUP_SORT numbering as follows:

  • 01  HeadingC
  • 02  HeadingD
  • 03  HeadingB
  • 04  HeadingA


You then need to open up your library's "Modify View", and under the "Group By" options:

  • first group by the column: GROUP_SORT
  • then group by the column: GROUP_HEADING.

Lastly, you need to add the following code to your SharePoint page.
This will hide the GROUP_SORT heading:

.ms-gb {
    display: none;
}


DONE! Couldn't be simpler :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.