Tuesday, April 23, 2013

SharePoint: Content Query Webpart - OOB, Custom Fields, Custom Style with Table format

Objective: Quick tips for Content by Query Webpart (CQWP)

Out of Box:
  1. You can display consolidated data from different lists, libraries, blogs, task lists etc.
  2. Best way to implement is with Content Type. Ex: To fetch data from multiple lists with same columns, first create Site content type, assign to all those lists and in CQWP select the content type.
  3. By default, you can pick two columns; one as Title and other as Description. you can also set one of default styles available like below:


Adding Custom Fields:
General requirement is to display more columns from list or library in webpart. Its small trick -
    1. Add out of box CQWP webpart on page and assign the lists, content types etc.
    2. Now export the webpart to your local machine.
    3. Open the webpart either in SP designer or visual studio or as matter of fact in Notepad and search for "CommonViewField" property like below screen.
    4. Add your list columns which you wants to display addition to Title & Description(both added earlier so no need to repeat here):
    5. TIPS:  Here you have to use internal name. In my example, my column names are "Request Set Status" and "File Number".
    6. Save your webpart, import it back to SharePoint and add to page. You can delete your earlier out of box webpart which we added in step 1.

Adding Custom Style Sheet:  Once you added your own fields, I am sure you want to change the display/style of data. Here you go to change style:
  1. Go to site style library(under view all site content) and first take copy of ItemStyle.xsl as backup before you play with it.
  2. Now open the ItemStyle.xsl in either designer, visual studio or even notepad. This xslt contains all the out of box styles so don't get scare by its long complicated look.
  3. Create a copy of entire template section of name "Default" and in your copied section change name as suited to your need. Here I changed to "CustomStyle". Don't forget to change in Match attribute as well other wise it will reflect in all styles
  4. Now, add your additional columns(added in step 6 of earlier part of custom field) in the Item section as below. I have marked columns with horizontal yellow line.
  5. TIPS: Here you can notice that the columns internal names are slightly different format. That's how SharePoint except :) . So be careful here.
  6. You can play with HTML tags, CSS to give your own style,color etc
  7. To implement Table header and footer, you need to do couple of steps. As you can see in above picture, I have marked few lines with vertical yellow color. That will help in setting up table headers. You can change header as per your need in Header variable section.
  8. After completing all changes in ItemStyle.xsl, upload back to Style Libray.

Happy Learning!





Microsoft Reference Link: http://msdn.microsoft.com/en-us/library/aa981241(v=office.14).aspx

1 comment:

anonimous said...



My name is Melissa Vivian,I base in USA,Texas..My life is back!!! After 2 years of Broken marriage, my husband left me with two kids . I felt like my life was about to end i almost committed suicide, i was emotionally down for a very long time. Thanks to a spell caster called Dr Ogidi, which i met online. On one faithful day, as I was browsing through the internet,I came across allot of testimonies about this particular spell caster. Some people testified that he brought their Ex lover back, some testified that he restores womb,cure cancer,and other sickness, some testified that he can cast a spell to stop divorce and so on. i also come across one particular testimony,it was about a woman called Sonia,she testified about how he brought back her Ex lover in less than 2 days, and at the end of her testimony she dropped PROPHET OGIDI email address. After reading all these,I decided to give it a try. I contacted him via email and explained my problem to him. In just 48hours, my husband came back to me. We solved our issues, and we are even happier than before Dr ogidi, is really a gifted man and i will not stop publishing him because he is a wonderful man... If you have a problem and you are looking for a real and genuine spell caster to solve all your problems for you. Try Prophet ogidi at MIRACLECENTER110@GMAIL.COM anytime, he might be the answer to your problems. Here's his contact: MIRACLECENTER110@GMAIL.COM You can also call him or text him here:+12015913961