In this article I would detail more on how to use Content query webpart in SharePoint 2010, it has got a bit more enhanced and advanced than the CQWP (content query webpart) you found in SharePoint 2007; however you can easily get wrong on understanding how this works because of several reasons.
I had spent time looking around and wasting a lot of time to find articles on this, so I thought better to put together all these in a single place for you all...
If you search for CQWP mostly you would hit the MSDN site however you still might need to find other articles to understand it and get a grip. The primary question is …..
Q. Where do you use a CQWP, and basically When will you use this webpart?
Ans. Content Query Web Part could be used to create custom views of data that is queried from many sources, and present that data all in one place. After you add the Content By Query Web Part to a Web page, you can customize the Web Part's querying behaviours and also the look and feel to display data appropriately.
It can also be used in many scenarios, some examples below:
+ If you have a site collection with a root site and you want to bring in and display the most recent blog posts from all blog sites within its own site collection…. Yes you can use CQWP for this
+ If you want to bring in and show all the events in a group calendar on the root site from the sub-sites created below….. CQWP will do
+ You can also bring in data views from a document library or lists and filter it and show it dynamically.
So here I will guide you through on how to configure a CQWP and to bring in data with two examples :
Imagine that you want show a Group-Events calendar which will show all the events from the calendars which are added in site and sub-sites within a Site-collection. It would be really nice if we could do this easily ….without any custom coding; yes you can do that with CQWP or to aggregate data from all the "Announcement " list which exist in sites and sub- sites of a site collection and to show that on the root site of the site collection.
Now lets crack on with the Group-Events calendar…. You can achieve this in less than 5 minutes !!!!!
Open up your SharePoint team site or a publishing site .
Insert a CQWP webpart from the webparts list, you can find it in the "Content Rollup" category ( If you cannot find the webpart it means you have not enabled "SharePoint Publishing Infrastructure " feature . Search in internet or review this link to resolve http://social.technet.microsoft.com/Forums/en-US/sharepoint2010setup/thread/cd1203e6-0054-4e19-a690-7ef545d48290/
Once the webpart is added on to the site, Click on the "Edit Webpart" and this will open up the CQWP tool part pane.
Basically the key useful sections of this tool webpart are below:
- Query Section : In this section you will be able to mention the source of data which you can bring in, you can also mention about the filters you can apply on the data source.
- Presentation Section : In this section you will be able to mention about the "Grouping, Sorting" , Styles and most importantly "the fields to display" on the CQWP.
In the Query section, Select the first option "Show items from all sites in this site collection". In the List type select "calendar" . In the "Grouping and Sorting" select "Group Items by" - Title
Leave all the other fields as in the Query section as it is.
In the Presentation section select Group Style > Banded, if you are looking for a bit of styling.
In the Fields to display leave as it is, this is one of the key things ; the fields you see are the default values which are going to be in the CQWP, you can add more values to it however it needs XSLT editing.
That’s it ……….all done, now you can see your CQWP showing all the events in the site collection grouped and styled.
Now play around change the grouping fields or filter there are many things you can do with it…..
Now If you want to show contents from a specific list can you do something similar ?.... Yes
I will take you through the steps quickly…..
Create a custom list with site columns on it, I have quickly created a list with 2 columns on it "Name" and "Description".
Note: DO NOT create new columns from a list if you want to display your own fields. There is an MSDN article says about it but always remember to create Site columns for this.
Once your list is created, Click on the "Edit Webpart" and this will open up the CQWP tool part pane.
Expand "Query" section and select the source list from the browse button
Expand the "Presentation" section and go to the "Field to Display" section. By default SharePoint provides 4 fields to display Link, Image, Title and Description. Put "TitleDescription" in Title and "EmpName" in Description.
That's all the Content Query webpart will start displaying the values from these fields.
Note : Even though the help on the "Fields to display" says [Depending on the scope of your query, select one or more site or list columns whose values you want to show in the following display slots for this style, separating entries with a semicolon. To specify a column from a particular group, type the name of the group in square brackets after the column name. Ex: Column[Group]] you can display multiple fields by semi columns on these fields, this is NOT QUITE TRUE.
If you want to add more custom columns then you have to edit the XSLT style sheet file on the style library.
Hope this article helped you to get some insight on CQWP
CQWP is quite powerful, you can use this for many things -
If you like to format Content Query Webpart and give it a great look, check this Article :
Here is another one, How to use CQWP for a News Scroller , Scrolling Announcement -
Here are some links and site you can use to have a look :
Here is an Example of CQWP usage, the widget you see on the site is CQWP
Refer MSDN : http://blogs.msdn.com/b/ecm/archive/2010/05/14/what-s-new-with-the-content-query-web-part.aspx