Data View conditional formatting using SharePoint Designer
This article demonstrates how to use SharePoint Designer 2010conditional formatting to format items in a SharePoint (SPS 2010) list based on item metadata.
The example uses a standard SharePoint task list and formats tasks based on the due date. The end result is a list view sorted by due date with item text or background coloured to represent the number of days until the due date.
The Process
In this example I have started with a standard task list and have created a few sample items for testing / demonstration.
From the task list, create a new view, starting from the default “Active Items” view (filtered to only display incomplete tasks). The view created in the example is called “Active – Coloured”
Open the view using SharePoint Designer. Right click on the List View Web Part and select “Convert to XSL Data View”. This will automatically convert settings for the current view into data view parameters.
Once the Web Part has been converted into a Data View Web Part, click the “Title” field if an item in the list to select it. From the Data View menu, select “Conditional Formatting”. To set the background colour of a row using conditional formatting, select the row instead of the “Title” field.
Formatting Conditions:
1/ Set all tasks with a due date more than a week away to be Green
- Start by setting the field to Due Date, greater than (>) the current date [today]
- Important: click in the grey section to deselect condition once set. If this is not done, changes to the advanced expression may not be applied.
- Click “Advanced” to open the “Advanced Condition” dialog.
- Add -7 before the last parenthesis in the start of the expression. See example below, the change is in bold:
number(translate(substring-before(@DueDate,'T'),'-','')-7) > number(translate(substring-before($Today,'T'),'-',''))
- Press “OK”. --> Condition should read "Using advanced expression"
-Press “OK”. --> Modify Style dialog should appear. Set required styles (font color to green in this case)
You may receive a “Site Definition Page Warning” message after customising the data view, or when saving the page. This has been fine in the past for me as I have not detached the masterpage and the style sheet remains linked to the page, so the page layout and any styles remain. If you are not sure, click the “About SharePoint site definitions” link on the dialog to get more information.
Note: To detect if a site has customised pages, SharePoint Designer provides necessary reporting features. To access the features, select “Reports” from the “Site” menu, then “Customised Pages”. For more detailed instructions, see the following article;
SharePoint Designer (2007) - Run reports for all sites programmatically. The article also demonstrates a method of performing reporting using SharePoint Designer for all sites in a site collection.
2/ Set all tasks with a due date less than a week, but more than 3 days away to yellow
- repeat (create new condition for the title field or row background) with less than or equal to -7 as condition. Advanced expression below:
number(translate(substring-before(@DueDate,'T'),'-','')-7) <= number(translate(substring-before($Today,'T'),'-',''))
3/ Set all tasks with a due date less than a week, but more than 3 days away to orange
Repeat with less than or equal to -3 as the condition. Advanced expression below:
number(translate(substring-before(@DueDate,'T'),'-','')-3) <= number(translate(substring-before($Today,'T'),'-',''))
4/ Set all tasks due today (1 day) to red
- Repeat with less than or equal to -1 as condition (include the -1). Advanced expression below:
5/ Set overdue tasks text to bold (already red from the previous condition)
- No advanced expression is required for this condition. Using the “Condition Criteria” dialog, simply set the field to the due date and the condition to less than the current date ( @DueDate < [Today] ).
The title for each task in the list should now be coloured dynamically based on the due date. The same method can be used to format items based on priority or most other columns.
The example uses a standard SharePoint task list and formats tasks based on the due date. The end result is a list view sorted by due date with item text or background coloured to represent the number of days until the due date.
The Process
In this example I have started with a standard task list and have created a few sample items for testing / demonstration.
From the task list, create a new view, starting from the default “Active Items” view (filtered to only display incomplete tasks). The view created in the example is called “Active – Coloured”
Open the view using SharePoint Designer. Right click on the List View Web Part and select “Convert to XSL Data View”. This will automatically convert settings for the current view into data view parameters.
Once the Web Part has been converted into a Data View Web Part, click the “Title” field if an item in the list to select it. From the Data View menu, select “Conditional Formatting”. To set the background colour of a row using conditional formatting, select the row instead of the “Title” field.
Formatting Conditions:
1/ Set all tasks with a due date more than a week away to be Green
- Start by setting the field to Due Date, greater than (>) the current date [today]
- Important: click in the grey section to deselect condition once set. If this is not done, changes to the advanced expression may not be applied.
- Click “Advanced” to open the “Advanced Condition” dialog.
- Add -7 before the last parenthesis in the start of the expression. See example below, the change is in bold:
number(translate(substring-before(@DueDate,'T'),'-','')-7) > number(translate(substring-before($Today,'T'),'-',''))
- Press “OK”. --> Condition should read "Using advanced expression"
-Press “OK”. --> Modify Style dialog should appear. Set required styles (font color to green in this case)
You may receive a “Site Definition Page Warning” message after customising the data view, or when saving the page. This has been fine in the past for me as I have not detached the masterpage and the style sheet remains linked to the page, so the page layout and any styles remain. If you are not sure, click the “About SharePoint site definitions” link on the dialog to get more information.
Note: To detect if a site has customised pages, SharePoint Designer provides necessary reporting features. To access the features, select “Reports” from the “Site” menu, then “Customised Pages”. For more detailed instructions, see the following article;
SharePoint Designer (2007) - Run reports for all sites programmatically. The article also demonstrates a method of performing reporting using SharePoint Designer for all sites in a site collection.
2/ Set all tasks with a due date less than a week, but more than 3 days away to yellow
- repeat (create new condition for the title field or row background) with less than or equal to -7 as condition. Advanced expression below:
number(translate(substring-before(@DueDate,'T'),'-','')-7) <= number(translate(substring-before($Today,'T'),'-',''))
3/ Set all tasks with a due date less than a week, but more than 3 days away to orange
Repeat with less than or equal to -3 as the condition. Advanced expression below:
number(translate(substring-before(@DueDate,'T'),'-','')-3) <= number(translate(substring-before($Today,'T'),'-',''))
4/ Set all tasks due today (1 day) to red
- Repeat with less than or equal to -1 as condition (include the -1). Advanced expression below:
number(translate(substring-before(@DueDate,'T'),'-','')-1) <= number(translate(substring-before($Today,'T'),'-',''))
5/ Set overdue tasks text to bold (already red from the previous condition)
- No advanced expression is required for this condition. Using the “Condition Criteria” dialog, simply set the field to the due date and the condition to less than the current date ( @DueDate < [Today] ).
The title for each task in the list should now be coloured dynamically based on the due date. The same method can be used to format items based on priority or most other columns.
- Get link
- X
- Other Apps
This article has been copied directly from one of my own, and is a breach of copyright. Please remove.
ReplyDeleteOriginal article: http://blog-sharepoint.blogspot.com/2009/05/data-view-conditional-formatting-using.html
Data View Conditional Formatting
sorry!!!!!
ReplyDelete