Reputation: 1672
I'm currently working on a Web Part that renders specific elements which properties are taken from a SharePoint List.
I'm planning to add a Field in SP List that will allow the SharePoint user to enter a number to specify the Order in which the elements will be rendered.
Question: What is the best way to implement this (keeping in mind that user may enter the same value twice or omit a number in sequence without knowing it)?
Example: we have elements and their Order value: A 1
, B 2
, C 3
, D 4
, E 5
.
If a user changes the Order value to: A 1
, B 4
, C 3
, D 4
, E 5
, the elements should be rendered in order: A
, C
, B
, D
, E
.
And if a user changes the Order value to: A 1
, B 7
, C 3
, D 4
, E 5
, the elements should be rendered in order: A
, C
, D
, E
, B
.
Upvotes: 2
Views: 5727
Reputation: 2267
This is the easiest solution. Activate linkedlist reorder button. https://pgbhoyar.com/2013/05/15/how-to-reorder-sharepoint-list-items-using-custom-codepowershell-and-sharepoint-designer-in-sharepoint-2010-and-sharepoint-2013-2/
Upvotes: 0
Reputation: 707
There is out-of-the box solution for list items reordering in SharePoint 2010.
http(s)://yousiteurl/_layouts/Reorder.aspx?List=ListGUID
After you reorder your items you can use CAML query to order by your items using item["Order"].
You can call this page in a modal dialog on you page or integrate this in the ribbon using custom actions.
More information how to do this can be found here.
Hope it helps,
Andrew
Upvotes: 1
Reputation: 1206
I would recommend you to use SPQuery
, it is also supposed to be more efficient.
When you use SPQuery you can specify OrderBy
as you wish.
Here is an example of using it: http://msdn.microsoft.com/en-us/library/ms457534(v=office.14).aspx
Upvotes: 1
Reputation: 32541
If you create a new SPField
to store the list items order, you must be aware that this values will not be customizable per user. They are assigned to the list items and are the same for all the users.
I believe you should take a look at the Creating a Web Part with Custom Properties topic. You could map the item IDs with a custom ordinal sequence, personalized per user. Then, you could override the default order and with the help of some client scripting, you could rearrange the items. Of course, things could get complicated when the items are displayed using pagination.
But the more realistic way to approach your requirement would be to create several fields (CustomOrder1
, CustomOrder1
etc) and subsequently, some custom views which are sorted based on these fields.
Upvotes: 0