简体   繁体   中英

how to filter list items by user/group column in sharepoint?

I have a list that has a user/group column that I want to filter by (the column name is: USERS). how do I get only the items in the list where the current user exists in the USERS column?

If it is simply a customized view, look at a Tasks list and the My Items view for reference.

You should be able to go the the Filter section in the view and have a filter that has "is equal to" "[Me]". However, it sounds like this is a multi-valued field so maybe you can get away with "contains" "[Me]".

Another considerations is looking into Audiences if you have MOSS. The Content Query Web Part is capable of filtering list items based on the audience.

if (item["users"] != null)
{
    //get USERS field for item
    SPFieldUserValueCollection fieldUserValueCollection = new SPFieldUserValueCollection(web, item["users"].ToString());

    //go over the users/groups collection
    foreach (SPFieldUserValue fieldUserValue in fieldUserValueCollection)
    {
        if (fieldUserValue.User == null) //group
        {
            if (web.SiteGroups.GetByID(fieldUserValue.LookupId).ContainsCurrentUser)
            {
                bolItemGood = true;
                break;
            }
        }
        else //user
        {
            if (fieldUserValue.User.IsDomainGroup) //domain group
            {
                if (web.IsCurrentUserMemberOfGroup(fieldUserValue.LookupId))
                {
                    bolItemGood = true;
                    break;
                }
            }
            else //sp user
            {
                if (fieldUserValue.User.LoginName == Context.User.Identity.Name)
                {
                    bolItemGood = true;
                    break;
                }
            }
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM