Pages

Thursday, June 5, 2014

SharePoint List - Re Order Items with OOB Feature


This is a very common request from client when we do create them custom SharePoint lists. “How can I re-order the list?” In fact, you could create an extra column in your custom list via SharePoint Designer (SPD) or via your internet browser. Add a new column and have it as a “Number” field, name it “Display Order” and start identifying the order of each list item. Well, but we are going to use another way. The little trick I am going to show works perfectly in MOSS 2007, SharePoint 2010 and 2013.

For this, we can go with One of the SharePoint hidden pages which resides in Layouts Folder.  reorder.aspx page which will allows to re-order your list items. 

Specify {SiteUrl}/_layouts/Reorder.aspx?List={ListId}

Now you will see the List Items Displaying with its Only Title and a dropdown Column like below.

In SP 2013,

In SP 2010,


Once you the Order, it will get effected the List. But when you see in UI, you might still see the Items not displayed in order what you did in earlier step. For this, as by default in All Items Page, items are ordered by ID it will consider that one. Here I want to point that there is one Field named as ORDER which will be available as OOB field in any List and this will be in Hidden State.

Make this Hidden Field as Visible, using Powershell or if custom list adding in your schema.xml itself.

Using Powershell,

# Change List Schema to unhide order field.
$siteUrl = "yourSiteUrl;
$listTitle = "yourListTitle";
$site = Get-SPSite -Identity $siteUrl;
$web = $site.OpenWeb();
$list = $web.Lists[$listTitle];
$field=$list.Fields["Order"];
$field.SchemaXml=
$field.SchemaXml.Replace("Hidden=""TRUE""","Hidden=""FALSE""");
Write-Host "-------------------------------------"
Write-Host "Order field is set to visible in
list :  " $list.Title -foregroundcolor Green -nonewline
Write-Host " in the site  : " $site.Url -foregroundcolor Green
Write-Host "-------------------------------------"
$web.Dispose();
$site.Dispose();



If you are having your list in the visual studio solution you can add
<Field ID="{ca4addac-796f-4b23-b093-d2a3f65c0774}" ColName="tp_ItemOrder" RowOrdinal="0" Name="Order"
DisplayName="Order" Type="Number" Hidden="FALSE" SourceID="http://schemas.microsoft.com/sharepoint/v3"
StaticName="Order" FromBaseType="TRUE" /> 

to the <Fields> collection of the Schema.xml

Now go to your respective view settings and change the Sort by ORDER Column


Now go to your list and view the Items, you will observe all Items are in ORDER wise which you specified in ReOrder Page.

This way we can understood, where lot of things we can do able without coding/logic in SharePoint if we are in the SharePoint OCEAN...!

No comments:

Post a Comment