The functionality to “Reorder list items” is inbuilt for “Links” lists both in SharePoint 2010 and SharePoint 2013.
“Change Item Order” option in SharePoint 2013 Links List.
“Change Item Order” option in SharePoint 2010 Links List.
How does this “Change Item Order” button work?
SharePoint uses hidden column “order” to set the order. When we select the “Change Item Order” option, SharePoint uses “/_Layouts/Reorder.aspx?List=ListGUID” page to reorder the list items.
But this wonderful feature is hidden for other list templates and only available with OOTB Links Lists. I wonder why?
In this blog post I have listed different methods we can use to enable this feature for other lists.
Method 1: Use Console Application/PowerShell script. This method is preferable because we can reuse it for different lists with ease. We just need to provide the site url and the list name.
C# Console Application: You can download this file from here.
using Microsoft.SharePoint; namespace ReOrderSharePointListItems { class ReOrderSharePointListItems { static void Main(string[] args) { using (var site = new SPSite("yourSiteCollectionUrl")) { using (var web = site.OpenWeb()) { var list = web.Lists["yourListTitle"]; SetButton(list, web); SetOrder(list, web); } } } /// <summary> /// Set Button "Change Item Order" in /// Top Ribbon of List /// </summary> /// <param name="list"></param> /// <param name="web"></param> static void SetButton(SPList list, SPWeb web) { list.UserCustomActions.Clear(); SPUserCustomAction action = list.UserCustomActions.Add(); action.Location = "CommandUI.Ribbon"; action.Sequence = 85; action.Title = "PS.OrderItems"; action.Rights |= SPBasePermissions.EditListItems; action.CommandUIExtension = string.Format( @"<CommandUIExtension> <CommandUIDefinitions> <CommandUIDefinition Location=""Ribbon.ListItem.Actions.Controls._children""> <Button Id=""ReOrderAction.Button"" TemplateAlias=""o1"" Command=""ReOrderCommand"" CommandType=""General"" LabelText=""Change Item Order"" Image16by16=""/_layouts/1033/images/formatmap16x16.png"" Image16by16Top=""-192"" Image16by16Left=""-144"" Image32by32=""/_layouts/1033/images/formatmap32x32.png"" Image32by32Top=""-192"" Image32by32Left=""-288""/> </CommandUIDefinition> </CommandUIDefinitions> <CommandUIHandlers> <CommandUIHandler Command =""ReOrderCommand"" CommandAction=""{0}/_layouts/reorder.aspx?List={1}"" /> </CommandUIHandlers> </CommandUIExtension>", web.ServerRelativeUrl.TrimEnd('/'), list.ID); action.Update(); } /// <summary> /// Order Default view by field "order" /// </summary> /// <param name="list"></param> /// <param name="web"></param> static void SetOrder(SPList list, SPWeb web) { SPView view = list.DefaultView; view.Query = @"<OrderBy><FieldRef Name=""Order"" Ascending=""TRUE""/></OrderBy>"; view.Update(); } } }
PowerShell Script: You can download this script from here.
[void] [System.reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | out-null # Add "Change item Order" button at target List $siteUrl = "yourSiteCollectionUrl"; $listTitle = "yourListTitle"; $site = Get-SPSite -Identity $siteUrl; $web = $site.OpenWeb(); $list = $web.Lists[$listTitle]; $list.UserCustomActions.Clear(); $action = $list.UserCustomActions.Add(); $action.Location = "CommandUI.Ribbon"; $action.Sequence = 85; $action.Title = "PS.OrderItems"; $action.CommandUIExtension = [string]::Format( "<CommandUIExtension> <CommandUIDefinitions> <CommandUIDefinition Location=""Ribbon.ListItem.Actions.Controls._children""> <Button Id=""ReOrderAction.Button"" TemplateAlias=""o1"" Command=""ReOrderCommand"" CommandType=""General"" LabelText=""Change Item Order"" Image16by16=""/_layouts/1033/images/formatmap16x16.png"" Image16by16Top=""-192"" Image16by16Left=""-144"" Image32by32=""/_layouts/1033/images/formatmap32x32.png"" Image32by32Top=""-192"" Image32by32Left=""-288""/> </CommandUIDefinition> </CommandUIDefinitions> <CommandUIHandlers> <CommandUIHandler Command =""ReOrderCommand"" CommandAction=""{0}/_layouts/reorder.aspx?List={1}"" /> </CommandUIHandlers> </CommandUIExtension>", $web.ServerRelativeUrl.TrimEnd('/'), $list.ID); $action.Update(); $view = $list.DefaultView; $view.Query = [string]::Format("<OrderBy><FieldRef Name=""Order"" Ascending=""TRUE""/></OrderBy>"); $view.Update(); Write-Host "-------------------------------------" Write-Host "Change item order button added successfully for the list : " $list.Title -foregroundcolor Green -nonewline Write-Host " in the site : " $site.Url -foregroundcolor Green Write-Host "-------------------------------------" $web.Dispose(); $site.Dispose();
Method 2: Use SharePoint designer and PowerShell.
1. Since “order” column is hidden, we need to use following PowerShell script to make this field visible. Once this field is visible, we can use it in List Views. You can download this script from here.
# 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();
2. Open the list in SharePoint Designer
3. Click on “Custom Actions” and then select “View Ribbon”
4. Enter following information.
- Name : “Change Item Order”
- Navigate to URL: {SiteUrl}/_layouts/Reorder.aspx?List={ListGUID}
- Button Image URL (16×16): {SiteUrl}/_layouts/1033/images/formatmap16x16.png
- Button Image URL (32×32): {SiteUrl}/_layouts/1033/images/formatmap32x32.png
5. Click OK. This will add the custom action in the list ribbon as shown below.
6. Next step is to modify the default view of the list and sort the items by field “Order”.
7. All set.
Note : “Change Item Order” option does not modify the version history of list items. So if you are using Content Deployment, reordering the list items will not move changes to target environment.
Quality content is the crucial to attract the visitors to go to see the website, that’s what this website is providing.
LikeLike
Weird things when I change the items order it assigns all the changed links order = 350.
LikeLike
Weird thing, when I change an items order the order number becomes 350 for all the items that I change the position.
For example
link a is 100.
link b is 200
link c is 300
link d is 400
if I change the order of the links all order number will become 350.
LikeLike
Pingback: How to ReOrder SharePoint List Items | My Blog
very neat explanation keep it up
LikeLike