Adding Columns

The built-in list templates give you most of what you need, but you'll quickly find that you have to make some changes to get what you want. I gave a quick example of how to create and customize a list in the Phone List example in Chapter 1, so I won't repeat that information here, but I will go into more detail about the types of changes you can make and why you make them:

  • Add columns to gather additional information.

  • Add calculated columns to display information in different ways.

  • Add choice or look-up columns to provide new ways to group or filter items.

The following sections describe those tasks in detail.

Adding Columns to Gather Information

You can extend any list by adding new columns to it. Let's look at the Phone List sample again to show how that works. To add an Assistant column to the Phone List:

  1. Navigate to the Phone List sample list created in Chapter 1.Tip: you can navigate to a list by clicking on the title bar of the web part that displays a list.

  2. On the list toolbar, click Settings → Create Column. SharePoint displays the Create Column page.

  3. Complete the page as shown in Figure 4-3 and click OK. SharePoint adds a new text column to the list.

Adding an Assistant column to the Phone List

Figure 4-3. Adding an Assistant column to the Phone List

Once you add an Assistant column, it's up to you to add data for each row in the list. Because you selected Add to default view in Figure 4-3, Assistant automatically shows up in the main view of the list, so you can just click Actions → Edit in Datasheet to fill in the new column. But don't do that yet! I'll change and expand this example shortly.

Assistant is a simple text column. Figure 4-3 lists the special uses for some of the other column types. Most of them are obvious, but I'll explain the Calculated and Lookup columns in detail in the following sections.

Adding Calculated Columns

Use calculated columns to bring together values from other columns. For example, the Phone List contains a Full Name column that is a single line of text. Since the list already has First Name and Last Name in it, it makes more sense to create Full Name out of those two columns. To do that:

  1. On the Phone List toolbar, click Settings → Create Column. SharePoint displays the Create Column page.

  2. Complete the page as shown in Figure 4-4 and click OK. The formula shown in Figure 4-4 is =[First Name] & " " & [Last Name]. SharePoint adds a new calculated FullName column to the list.

Adding a calculated column to a list

Figure 4-4. Adding a calculated column to a list

Tip

To get help using formulas, display the SharePoint Help and click "Formulas and functions." To display SharePoint Help, use the following link: ./_layouts/help.aspx?Key=NavBarHelpHome.

Notice that I told you to name the column "FullName." The Phone List already has a "Full Name" column, and you can't have two columns with the same name! We're not using the Full Name column, so let's delete it. To delete a column:

  1. On the list toolbar, click Settings → List Settings. SharePoint displays the Customize page.

  2. Scroll down and click Full Name in the Columns list. SharePoint displays the Change Column page.

  3. Scroll to the end of the page and click Delete. SharePoint warns you that data for this column will be deleted. Click OK to delete the column.

Adding a Choice, Lookup, and Yes/No Columns

Use the Choice, Lookup, and Yes/No column types to structure the information entered in the column. In Chapter 1, I added a Department Choice column to the Phone List. I used the Choice type because I wanted to make sure the entries were consistent—users can only choose from the selections in the list of departments I provided. That prevents misspelled or incorrect department names and allows the Phone List to be grouped by department.

Choice, Lookup, and Yes/No column types have these advantages:

  • Values are consistent, so grouping and filtering on these columns is effective.

  • It's easier to enter values, since choices are provided as drop-down lists or multiple-choice selections.

  • Choices can be shared across lists and sites.

Let's continue with the Phone List sample a bit more and change the Assistant column from a text column to a lookup. You can't change the type of a column once it's created, so we'll have to delete the Assistant column and re-create it with the new type. (Remember, I told you not to enter data in it!) To change the Assistant column:

  1. On the Phone list toolbar, click Settings → List Settings. SharePoint displays the Customize page.

  2. Scroll down and click Assistant in the Columns list. SharePoint displays the Change Column page.

  3. Scroll to the end of the page and click Delete. SharePoint warns you that data for this column will be deleted. Click OK to delete the column.

  4. On the Change Column page, click Create Column. SharePoint displays the Create Column page.

  5. Complete the page as shown in Figure 4-5 and click OK to create the new Assistant column.

Creating a new Assistant column as a Lookup type

Figure 4-5. Creating a new Assistant column as a Lookup type

Now, you can fill out the Assistants in the phone list. To do that:

  1. On the Phone list toolbar, click Actions → Edit in Datasheet.

  2. Click the Assistant column and then click the down arrow on the right side of the column to drop-down the list of choices.

  3. Click the choice to select the assistant as shown in Figure 4-6.

Using the Lookup column

Figure 4-6. Using the Lookup column

The Assistant column is a circular lookup. That is, you can choose any name provided that the person is already entered in the Phone List. You can use a lookup to pull data from another list in the site by selecting a different source list and column name.

Why Use a Lookup?

Lookup and Choice column types serve similar purposes. Both provide choices from a list of values. With Choice columns, the values are entered directly in the column settings. With Lookup columns, the values come from another list.

Why go to the trouble of setting up a whole list just for a lookup? Because changes to the lookup list appear automatically in the Lookup column. To see how that works:

  1. Select Charles Murphey as an assistant in the first row of the Phone List as shown in Figure 4-6, and then change his first name to Charley in the fifth row of the Phone List.

  2. Click Actions → Show in Standard View, and "Charley Murphey" now appears in the first row.

  3. Finally, click on Charley Murphey in the first, and you'll see his contact details. Lookups link lists together!

In this case, you've got to enter assistants before you enter managers (otherwise, you won't be able to find their assistant). That's always true of lookups: the source list must contain the values you want to look up before you can fill out the destination list.

Lookups can be used across any list or library in the current site. For example, you might add a Lookup column to a Task List that gets its values from a library containing Contracts. Each task then links to the contract that spells out the exact terms of the task as shown in Figure 4-7.

Using Lookup columns to drill down to a contract from a task list to a document

Figure 4-7. Using Lookup columns to drill down to a contract from a task list to a document

Get Essential SharePoint 2007, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.