Nick Grattan's Blog

About Microsoft SharePoint, .NET, Natural Language Processing and Machine Learning

Re-ordering All-day Items in a Calendar

with 8 comments

By default, all-day items will be displayed in the order determined by their physical location in the database table:

CalSort1

A more natural order would be alphabetic – to change the sort order you’ll need to create a list template, modify the manifest file to add the sort order and then load a new list template. Here goes….

  • First navigate to a standard Calendar list and select the Settings + List Settings menu command.
  • Select the Save List as Template command.
  • Enter a name, such as “SortedCalendar” for the filename and template name and click OK.
  • Click the list template gallery link on the “Operation Completed Successfully” form.
  • You will be taken to the “List Template Gallery”. Click the “Sorted Calendar” link for the gallery you just created. Save this down to the file sytem.
  • Use Windows Explorer to rename the file from “SortedCalendar.stp” to “SortedCalendar.stp.cab” – it really is a CAB file!
  • In Windows Explorer double click the CAB file – you will find a single file called mainifest.xml. Copy this into the file system.
  • Use an XML editor (such as Visual Studio) to open the XML file.
  • Search for the following line (look for calendar.aspx):

<View Name=”{895B6132-0327-4FAB-A34B-EFB57FD5E542}” DefaultView=”TRUE” Type=”CALENDAR” RecurrenceRowset=”TRUE” DisplayName=”Calendar” Url=”Lists/Calendar2/calendar.aspx” Level=”1″ BaseViewID=”2″ ContentTypeID=”0x” ImageUrl=”/_layouts/images/events.png”>

  • You now need to look for the query associated with this view. It will be about ten to fifteen lines below the line shown above and looks like:

           <Query>
              <Where>
                <DateRangesOverlap>
                  <FieldRef Name=”EventDate”/>
                  <FieldRef Name=”EndDate”/>
                  <FieldRef Name=”RecurrenceID”/>
                  <Value Type=”DateTime”>
                    <Month/>
                  </Value>
                </DateRangesOverlap>
              </Where>
            </Query>

  •  Edit the CAML query to include a “OrderBy” clause:

            <Query>
              <Where>
                <DateRangesOverlap>
                  <FieldRef Name=”EventDate”/>
                  <FieldRef Name=”EndDate”/>
                  <FieldRef Name=”RecurrenceID”/>
                  <Value Type=”DateTime”>
                    <Month/>
                  </Value>
                </DateRangesOverlap>
              </Where>
              <OrderBy>
                <FieldRef Name=”Title”/>
              </OrderBy>
            </Query>

This will cause the results to be sorted by the “Title” field.

  • Save the file manifest.xml.

The manifest.xml file now needs to be added back into the CAB file using the MAKECAB application. To make this tool more accessible run a Visual Studio Command Prompt:

  • Select the Start + All Program + Visual Studio 2005 + Visual Studio Tools + Visual Studio 2005 Command Prompt.
  • At the command prompt navigate to the folder where the manifest and CAB files are located and enter the following:

makecab manifest.xml SortedCalendar.stp.cab

  • Rename “SortedCalendar.stp.cab” to “SortedCalendar.stp”.
  • Return to the “List Template Gallery” in SharePoint.
  • Click the Upload button and upload the “SortedCalendar.stp” file.

You can now test the new list template by creating a new list– you will find the new listtemplate listed in the Tracking section on the “Create” form. All day events will now be alphabetically sorted by “Title”. Phew!

Advertisements

Written by Nick Grattan

January 23, 2008 at 9:13 pm

8 Responses

Subscribe to comments with RSS.

  1. I think that in the last paragraph of this post you switched from list templates to talking about site templates. Other than that so far so good and I am giving it a try.

    DHolder

    January 23, 2008 at 11:10 pm

  2. Thanks for the correction. Also, I think you’re right about the default ordering. I state that it’s determined by the order in which they are added. However, it’s more likely to be “no order” based on the order the records end up in the underlying SQL Server table. Regards, Nick.

    nickgrattan

    January 24, 2008 at 7:02 am

  3. can this be done for items that are not all day?

    aspear

    June 23, 2009 at 5:43 pm

  4. Also, this doesn’t work if it’s a recurring item…

    Mike

    December 8, 2009 at 8:35 pm

  5. Is there any way to group a multiday event with a single day event? For example:

    Project AA has a M-F meeting and an additional Meeting on Wednesday.
    Projects BB and CC have Tu-Th meetings.

    Is there anyway to have the calendar show:

    M T W T F
    AA AA AA AA AA
    AA
    BB BB BB
    CC CC CC

    shaun

    February 24, 2010 at 4:32 pm

  6. This does not seem to work with SharePoint 2010. Has anyone gotten it to work?

    Aaron Barker

    July 18, 2011 at 5:22 pm

  7. Also wondering if anyone has gotten this working with Sharepoint 2010. Nothing i do seems to sort the columns.

    MikeC

    November 1, 2011 at 2:17 pm

  8. I tried the same, but its not working for me.
    i pasted my ListView here and i try to sort by Title, but its not working

    <View Name="{853EBAFB-D2CE-4EE7-8793-B27BA36323F5}" MobileView="TRUE" MobileDefaultView="TRUE" Type="CALENDAR" TabularView="FALSE" RecurrenceRowset="TRUE" DisplayName="Calendar"
    Url="/Lists/Calendar/calendar_copy(1).aspx" Level="1" BaseViewID="2" ContentTypeID="0x" MobileUrl="_layouts/mobile/viewdaily.aspx"
    ImageUrl="/_layouts/images/events.png"><Toolbar Type="Standard"/><ViewHeader/><ViewBody/><ViewFooter/><ViewEmpty/><ParameterBindings><ParameterBinding Name="NoAnnouncements"
    Location="Resource(wss,noXinviewofY_LIST)"/><ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)"/></ParameterBindings><ViewFields><FieldRef Name="EventDate"/><FieldRef Name="EndDate"/><FieldRef Name="fRecurrence"/><FieldRef Name="EventType"/><FieldRef Name="Attachments"/><FieldRef Name="WorkspaceLink"/><FieldRef Name="Title"/><FieldRef Name="Location"/><FieldRef Name="Description"/><FieldRef Name="Workspace"/><FieldRef Name="MasterSeriesItemID"/><FieldRef Name="fAllDayEvent"/></ViewFields><ViewData><FieldRef Name="Title" Type="CalendarMonthTitle"/><FieldRef Name="Title" Type="CalendarWeekTitle"/><FieldRef Name="Location" Type="CalendarWeekLocation"/><FieldRef Name="Title"
    Type="CalendarDayTitle"/><FieldRef Name="Location"
    Type="CalendarDayLocation"/></ViewData><Query><Where><DateRangesOverlap><FieldRef Name="EventDate"/><FieldRef Name="EndDate"/><FieldRef Name="RecurrenceID"/><Value Type="DateTime"><Month/></Value></DateRangesOverlap></Where><OrderBy><FieldRef Name="Title"/></OrderBy></Query></View>

    Any one please help me

    Arunkumar

    January 29, 2013 at 11:32 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: