tabs

Thursday, July 18, 2013

Content Query Web Part ,Adding more than three filters:

Even though people use CQWP to roll up content from their sites or subsites, they feel little awkward noticeing that the UI part of the tool support only three filters.
So i am here in this post with a simple solution.
One of the frequent ways to to allow filters more than three is to override the QueryOverride property of the webpart. Inorder to achieve this follow the following four simple steps:

  • Firstly,Webpart should be exported to the File system.
  • It could be done,with the page in edit mode,expand the Content Query Web Part menu and select Export and save the web part to te local file syatem.
  • Secondly,build the CAML required to filter the list.
  • Now update the QueryOverride property.
  • If I need four filters (one for each custom column) I could use the following value in the QueryOverride property:
     <property name="QueryOverride" type="string">
              <![CDATA[
               <Where>
                  <And>
                     <And>
                        <BeginsWith>
                           <FieldRef Name='NewColumn1' />
                           <Value Type='Text'>NewColumn1 Item1</Value>
                        </BeginsWith>
                        <BeginsWith>
                           <FieldRef Name='NewColumn2' />
                           <Value Type='Text'>NewColumn2 Item1</Value>
                        </BeginsWith>
                     </And>
                     <And>
                        <BeginsWith>
                           <FieldRef Name='NewColumn3' />
                           <Value Type='Text'>NewColumn3 Item1</Value>
                        </BeginsWith>
                        <BeginsWith>
                           <FieldRef Name='NewColumn4' />
                           <Value Type='Text'>NewColumn4 Item10</Value>
                        </BeginsWith>
                     </And>
                  </And>
               </Where>
              ]]>
            </property>
  • Finally ,Import the webpart to the webpart page.
  • With the web part page in Edit Mode, click the Add a Web Part link to open the Web Part Pane.
    Under the Upload a Web Part section select the modified web part file in the local file system and click Upload. This will load your web part under the Imported Web Parts category. Select your web part and click Add to import the web part into the web part page.

    Note:

    There could be a chance that some of the elements in the UI getting disabled ,when we try to use the overrides property within the CQMP.In this case we cannot add more than three queries from Content Query Tool part.

No comments:

Post a Comment