Friday, May 11, 2007

SharePoint Designer Article 2 - Creating an XSLT DataView for a sharepoint list

An XSLT dataview is a great way to modify the look and feel of displayed data in a sharepoint site. The dataview web part is able to display data from either sharepoint lists, or from external data sources.

This article will focus on how to create a simple xslt dataview for a sharepoint list.



First we will create a sharepoint list - Contacts, and fill it with some sample data:





Now, lets create a new page that we will use to create the xslt dataview in:





Open the page in SharePoint Designer (see my previous article if you forgot how - you will need to detach it from the page layout first!).





Now we can add the contacts list to the page using sharepoing designer. You can also do that from the browser before opening the page in sharepoint designer if you prefer:





Let us work in a clean environment - change the properties of the web part so it doesn't display the toolbar. Annoyingly, in sharepoint designer this means you have to open the dropdown menu for the web part (looks like a list icon) and select "change layout":







Select not to show a toolbar.

Now we can transform the web part to an XSLT dataview. Just right-click the web part and choose "convert to xslt data view":





The page should flash and then the web part will appear again, only slightly different. A new menu will appear with a lot more options (filter, sort and group, paging, edit columns, change layout, data view preview, show with sample data, conditional formatting, web part connections, parameters, refresh dataview, dataview properties).
Now you can start playing with it!



In this article I will not go over all the options - I will just conclude by showing you the conditional formatting, and how to deploy the web part to another page in the site:



Click on "Conditional Formatting" in the common data view tasks menu:





The task pane on the right should change to the "Conditional Formatting" pane. Now we can click a row (any will do), and then click the "create" menu, and choose "apply formatting" from the menu:





Because we selected a row, we can apply formatting to that row based on rules we will now define in this screen:





In this example I chose the rule - when first name is "Ishai". Press OK to get to the formatting options:





I set the formatting to show my contact's row with a light blue background, in bold and in uppercase.

Save the file, and view it in the browser:





As you can see - it shows exactly what I wanted it. Now to deploy it to the home page of the site (which we didnt want to detach from the layout page):

In the browser, open the actions menu for the web part and click "export":





Now save the file to your desktop, and go to the homepage of the site. Switch to "edit page mode", click on "add a web part" in one of the zones, and then on the "advanced web part gallery and options" link at the bottom.

Use the dropdown at the top of the pane to switch to web part import pane:





Now, browse to the saved file and click the "upload" button. The web part should appear as an option in the pane. Drag and drop it to the zone you want it in:









And now you can click on "Exit Edit Mode" and see your wonderful new home page, that is still attached to it's layout page!




The next article will show how to do the same, but with external data!






12 comments:

Jag said...

Thanks Ishai

This article helped me a lot in learning the additional features of data view webpart. I tested it on my VM and amazed to see what i can do with it. Waiting for the article on pulling the external data using data view webpart.

Jag

Kailas said...

Jag,
We also can data externally in the dataview webpart by choosing a datascource like SQL server.

Thanks,
Kailas

Anonymous said...

This was an awesome article and I couldn't have found it at a better time! Thank you for taking time to put this together! :)

Phil said...

Hi Ishai...

Great post.

I'm trying to do the opposite.

I have a web part in which is displayed a database data. Well i want the data to be displayed in the sharepoint list(Workflow...).

How can i do that? Any idea?

Thanks Phil

whall said...

Great article! Is the one on external data completed?

btw, I got here via Google, looking for a way to put user profiles in a data view web part. Interestingly, I don't believe you covered the user profile database being the source, but I got here just the same...

Amod said...

Hi,

Thanks for wonderful tip. This helped me a lot.

I am facing strange issue. Even after I detach page and try to edit, I do not see edit screen in my designer. Is this some thing to do with designer settings?

Thanks in advance. AMD

FK said...

Great article!
However I am not able to see the "Convert to XSLT Data View" menu! Is that a permission issue? I do have contribute permissions on the site.

Anonymous said...

Exactly what I was looking for..
Thanks a lot for sharing your knowledge :)

Anonymous said...

If you need to implement custom sort ordering on the group headers in a grouped list:

http://tudorolariu.blogspot.com/2008/10/custom-group-order-in-sharepoint-list.html

It uses basically a changed version of the default XSLT.

Anonymous said...

I followed the steps for a document library. Whent I click on Edit dropdown for the item, I no longer get the options for Workflow, Version History. Any idea how to get it back ?

phils said...

Very cool! Thanks

Shaoqing said...

Very good article. it helps me to deploy my to solve my problem.