Subscribe:      
 

Document management with SharePoint - Part 2

Written By: Knox Cameron -- 7/13/2011 -- join -- contribute -- (8) comments -- printer friendly version

Rating: Rate --

Categories: Document Management, Project Management, SharePoint 2010, SharePoint Designer 2010, SharePoint Foundation 2010

< Prev - 1 | 2 | 3 | 4 | 5 | 6 | - Next > | Become a paid author

Color coding and formatting views

SPD gives you access to a lot of capabilities to enhance the presentation of views well beyond what you can do through the web interface. To take it to the max, and make views that really sing and dance, you will need to learn to use tools like JavaScript, jQuery, XSLT and CSS. But let's see what we can do without going too deeply into code!

To start with, let's add another column to our library to indicate document status in a review cycle. To keep it simple, we won't use SharePoint Server's publishing features, but just maintain our own tag indicating whether the document is in "Draft", "Under review" or "Final" status.

As we did in part 1, in the document library, use the Create Column button in the Library tab of the ribbon. Call the column "Review status", column type Choice, description "Stage in the review cycle". Enter the three choices "Draft", "Under review" and "Final". Leave the other options at their defaults and select OK.

As before, switch to Datasheet View and assign values for this new column to the documents in the library.

Now we will use SPD to colour code the items in the view. We will leave draft items in black, but shade items under review yellow and items that are final as green.

As before, select the option to modify the view in SharePoint Designer. In SharePoint Designer, by default the whole view is selected. Click on something within the body of the view - it doesn't matter what because we will be applying formatting to the whole row.

Now select the Format Row option in the Conditional Formatting drop-down of the Options tab in the ribbon.

Conditional Formatting task pane option

The first dialog asks for the condition(s) when the formatting will be applied. Select the field Review status and the value Under review.

Select column value for conditional formatting

Now select Set Style. The next dialog provides a raft of options for applying formatting in the html code of the view. For this example, select the Background category on the left and select a light yellow shade as the background color.

Dialog to apply formatting

  • When I first tried this, I selected a color in the Font category to change the color of the text. Although this appears to work in SharePoint Designer, when you go back to the view in the browser it doesn't work. The reason is that this dialog applies formatting commands to the table row, but any table row formatting is then overriden by font colors in the styles applied to table cells.

Select OK. If you scroll down the Design view, you should see that any entries for documents that are under review is shaded yellow. Repeat the same process to shade entries for documents that are final in light green.

Formatted view in SharePoint Designer

Save the view, close SharePoint Designer, and see what the view now looks like in the browser.

Colour coded view in the browser

Now let's fix the date display to just show the date, not the time. Again, use the option to edit this view in SharePoint Designer.

Unfortunately, there is no way to simply select the date format from a drop down, as there was with DataForm Web Parts in SPD 2007. We are going to have to edit the code of the formula. Select one of the modified dates in the design pane in SPD, and select the Formula button in the Options tab in the ribbon.

Option to edit formula in SPD

In the dialog, select the Text / String function category. Drag across the existing XPath expression so that it is all selected, then double click the string function in the list.

FormatDate function added to formula

This formats the existing date and time as a string. Now select the Date / Time function category. Again, drag across the existing XPath expression so that it is all selected, then double click the FormatDate function in the list.

Formula with FormatDateTime function added

As you can see from the description of the FormatDate function, it needs two more parameters: 'lcid' and 'formatflag'. The locale for US English is the number 1033, and the formatflag of 1 gives you a simple date. So type the following at the cursor position just inside the right parenthesis:

,number(1033),1

Completed FormatDate formula

Select OK. If you get an error, press Ctrl Z to undo the change and try again. Otherwise, you should see this:

Final view in SharePoint Designer

You can experiment with editing the formula to use different date formats, selecting one of the options for formatflag shown in the dialog. The formats given by formatflag values are documented here. For example, formatflag set to 3 gives a long date format like this:

View with long format date in SharePoint Designer

Once you have it the way you want it, save it in SPD, close SPD and go back to the browser to see the final result.

Final view in the browser

< Prev - 1 | 2 | 3 | 4 | 5 | 6 | - Next >



Learn more about SharePoint



Sponsor Information




Copyright (c) 2010-2017 Edgewood Solutions, LLC All rights reserved
privacy | disclaimer | copyright | advertise | contribute | feedback | about
Some names and products listed are the registered trademarks of their respective owners.


MSSharePointTips.com | MSSQLTips.com