Developer forum

Forum » Development » Users sorting in group

Users sorting in group

Jonas Mersholm
Reply

Hi there,

I've seen in the backend that i can sort users in groups, how do i implement this in the API (C#)?  Lets imagine i have a UserMangement.Group, with some UserManagement.User objects, how do i sort these in the group?

Best,

Jonas


Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

The code that runs in user management UI is this:

string[] userids = Strings.Split(Dynamicweb.Context.Current.Request("Users"), ",");
for (int i = 0; i <= userids.Length - 1; i++) {
    User user = user.GetUserByID(Convert.ToInt32(userids(i)));
    user.UserSortCollection.AddOrReplace(new UserSort(GroupID, i));
    user.Save();
}

Votes for this answer: 1
 
Jonas Mersholm
Reply

Hi Nicolai,

I got em' sorted now; but nomatter what API call i use to fetch the users in the group ( Group.Users / UserManagement.User.GetUsersByGroupID )  they are not sorted as specified?

Best

Jonas

 
Nicolai Pedersen
Reply

Hi Jonas

If you load the users in a usercollection and call SortBy(SortFields.Sorting, True, userGroup), you get the users sorted.

Remember a user can have multiple groups, so they are sorted relative to a group and the user can have different sorting value depending on the group

 

You must be logged in to post in the forum