Monday, June 1, 2015

BASICS OF CONTENT QUERY WEBPART: PART 1

CQWP has been around from ages but still I find it a most important component for any developer to rollup content over several different scopes, anywhere from a single list or library, to multiple list or libraries across an entire Site Collection.

CQWP is used for aggregating content from multiple data sources across your Web site, and then present it all in one place. On top of this you can present the information with your own custom UI by manipulating XSLT and CSS.

In this multi-part series I will be dwelling into various aspects of the CQWP

PART 1: Basics of CQWP

Part 1 : BASICS OF CONTENT QUERY WEBPART

In this part we will learn how to configure and customize the CQWP. This part is intended to the audience who have little or no experience with the CQWP.

  1. Adding CQWP to the Site
  2. Choosing Source or place from where data will be fetched.
  3. Learning the Additional Filters
  4. Presentation Section (Presenting the CQWP)
Adding CQWP to the Site

So let’s start by adding CQWP to our site.

  1. Open your SharePoint site and click the Site Actions drop-down and select Edit Page.
  2. Click on the Add a Web Part Link which open the Web part Gallery and then follow numbering to include the webpart.


  3. This will add the webpart and now to configure the webpart click “Edit the webpart” as shown

Choosing Source or place from where data will be fetched.
  1. Expand the Query Category in the Web Part Property Pane. This is basically used to choose your source and define list and content type based on that. There are three sources to choose from.
Learning the Additional Filters.

You can filter the data based on the columns/properties of the List. For E.g. I have a list “External News” with a column called “News Category” where I have category like “Political” and “Business”, now by default when I connect my list to CQWP then it will show all the items of the list as shown fig 4


So now if I want to show the “Political” news category then do as below, this will filter out the based on the “News Category” Political.



In SharePoint 2010, 2 new more advanced and dynamic way of filtering were introduced

PageFieldValue: Based on the field value present on the Page Layout, it will filter the items on the Content Query list. Let’s understand by example.
I have a Page Layout field called “Title” and based on the value of the Title I want to filter the “News Category” column of the List “External News”.
Now If I keep the page Title as “Business” and also changed the Content Query Filter as shown below then based on the page Title the data will be filtered from the List.



PageQueryString: This one I like the most. Let’s keep the same example. Define the filter as shown below [PageQueryString:] . Now using the variable name just pass the query string as shown below.
Using the query string parameter is better when you want to show different sets of results in a web part without having to make a new page for each different results set.


Presentation Section (Presenting the CQWP)
  1. Grouping and Sorting: You can select the column by which you want to group and sort the data.

    For e.g. I want to group the data based on the “News Category” column and sort based on “Created” column also u can tell whether you want to sort in Ascending or Descending order and limit the number of items to display.
  2. Styles: These define what information and how that information is displayed. I always feel styles section as a great value add to the CQWP. You can define style for the Group Style and Item Style, these styles are XSL templates, not CSS styles. You can create your own XSL templates. How to create styles will be part of the later series but just to show their power here is a small example.

    E.g. In the earlier list if I want to show the description of the title (In the list I have a column called Notes) and have the group heading as large text then this can be done as below.

Note: The “Fields to do display” section fields will change based on the “Item Style” you choose and you need to provide the column name from your list to display items.

I hope this walkthrough helps people configure and use the Content Query Web Part. Rest of the Article’s on other functionalities of the CQWP will be coming soon.

I'd be interested to hear and see examples of how people are using the web part. So, post your comments!

No comments:

Post a Comment