Searchable user list in Drupal using Views
Introduction
There are numerous reasons for wanting a list of members on your site. If you have a "social" site, then it is beneficial to have this list searchable so that members can find friends who have also registered (imagine if facebook didn't allow you to search for friends...) Fortunately, this can be done relatively simple in Drupal using just the views module.
Requirements
You will need to have Drupal installed and you will need the Views module. If you wish to implement the optional feature to do bulk operations on users, then you will also need the Views Bulk Operations module. If you need help with installing any of these, please refer to the documentation at drupal.org. It is recommended that you are at least somewhat familiar with the Views module, but we won't be doing anything too advanced here.
Creating the Member List
To create the member list, go to Administer -> Site Building -> Views and click the "Add" tab. Enter a name and description for the view (for this tutorial, I am using members_list for the name, and Members List for the description.) Be sure to specify "User" as the view type, and click "Next."
Select "Page" from the drop-down box and click "Add Display" to create a new page view. Under "Basic Settings," change the Title to "Members List" and change "Use pager" to use either the mini pager (previous and next buttons only) or full pager (includes links to pages.) Under "Page Settings," change the path to something like "members_list." You could add it to a menu using the menu field, but I prefer to add it manually to a menu.
Next, we will select what information should be visible in the member list. Click the '+' under "Fields" and select what you want to have visible. For example, I have "User: Name", "User: Picture", "User: Created date", and "User: Active" but you can customize this however you like. You may wish to customize the fields a bit, but usually the defaults are fine.
Click the '+' under "Sort criteria" and select "User: Name" in order to sort the list by the user names. You may select another or additional sorting criteria. If you continue with the optional bulk operations, you will be able to change the sort order by clicking the labels, so think of this as the initial sort method.
Finally, we are ready to make it possible to search the member list. Click the '+' under "Filters" and select the fields you wish to use for search criteria. These will likely include some of the fields you selected to display, but not necessarily all of them. For instance, you probably wouldn't search by picture, and searching by created date might not be very helpful either. Once you have selected the search fields, it is important to expose them. Do this by editing the field and clicking the "Expose" button. You may wish to make some other changes, such as modifying the label text, but make sure that "optional" is checked so that you may search by just one field if desired. Exposing the field allows users to set the search criteria.
At this point, your view should be ready, so be sure to save it (or else you'll lose all that work!!!) To test that it is working, go to the path you specified for the members list (ie. http://<yoursitename>/members_list. Initially, this will show you a list of all members. You can narrow the list by using the search fields at the top of the page. If this is all you want, then congratulations, you are finished. However, let's say that you want a way for your administrators to activate or deactivate users in bulk. Read on for how you can implement this.
Bulk Operations
This section explains how to perform bulk operations on users. This is helpful if you need to activate/block a number of users at once. You might want to have this as a separate view or page, just for admins, or you can add it to the memebers list we just created.
Install the Views Bulk Operations module and set the desired permissions. Note that VBO comes with an actions_permissions group, so take note of that. Once everything is set up, go to Administer -> Site Building -> Views and find our members_list view that we created above. Click the "edit" link to edit the view.
Under "Basic Settings," change the style from "Unformatted" to "Bulk Operations." In the style options, you can select which fields are sortable and which is the default sort field. This is nice as it allows you to re-sort the list based on different criteria. Set any options you wish, and select which operations an administrator should be allowed to perform on the users. Update, save, and you now have a searchable user list with bulk operations functionality!
Add the list to your menu
If you want to add the member list a menu, go to Administer -> Site Building -> Menus and select the menu you wish to add this to. Simple add a new link using the path you gave for the page, and you'll be all set.
