Change SortOrder of items

Jan 9, 2009 at 9:22 AM

how do i change (or swap) the sort order of 2 items. I tried to set the sortorder property and save the items via persister but that doesn't seems to work.


Jan 11, 2009 at 5:08 PM
There's some utility method in the N2.Utility class.
Jan 13, 2009 at 11:40 AM
I tried the utilty class but the move function does also not work.

Any ideas
Jan 14, 2009 at 6:23 PM
Edited Jan 14, 2009 at 6:23 PM
The methods requires the each returned items to be saved explicitly. Did you do that?
Mar 25, 2009 at 10:29 AM
Edited Mar 25, 2009 at 10:36 AM
Ok guys, I have a question about swapping items.

I have a list of items like this:
        IList<ContentItem> itemList = ....

I want to swap two items in that list with each other with the following code:
        Utility.MoveToIndex(itemList, item, index);

The two items are actually swapped with each other. I can see this in the debugger.

I tried the following to save these changes:
        IEnumerable<ContentItem> lijstje = Utility.UpdateSortOrder(itemList);
        foreach(ContentItem item in lijstje) {

But I think the changes are never saved because after another debug round (= page refresh) the list is exactly the same as when I started. In other words the items are not swapped.
What am I doing wrong and who can help me?

What I actually want is swapping the sortOrder property of two items...
Mar 25, 2009 at 6:20 PM
The utility methods updates the sort order on the items but doesn't save the changes to database. You'll need to iterate the returned collection and (n2.context.current.persister.)save each item yourself.