Thursday, August 22, 2013

Tiles view with CQWP

SharePoint 2013 includes a new list (App) "Promoted Links" that displays links in a tile based visual format.


My goal was to create a Promoted Links list but with some kind of filtering like Expiry on Announcement list. The prompted links doesn't provide with this option in the web part settings
or in the Tiles view:

I used the good old Content Query Web Part (CQWP) to achieve the tile view. The following are the steps:
1. Create a List with title, expiry, description and image columns
2. Update the ItemStyle.xsl file with following sample code: (fix the inline styles)

<xsl:template name="ListWithTitles" match="Row[@Style='ListWithTitles']" mode="itemstyle">
<xsl:variable name="SafeLinkUrl">
<xsl:call-template name="OuterTemplate.GetSafeLink">
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>
<div id="Div2" style="width: 160px; height: 160px;" class="ms-tileview-tile-root">
<div id="Div3" style="width: 150px; height: 150px;" aria-haspopup="true" class="ms-tileview-tile-content">
<a href="{$SafeLinkUrl}" >
<img height="150" class=" ms-positionRelative" style="visibility: visible; right: 219px;">
<xsl:attribute name="src" >
<xsl:value-of select="@Image" />
</xsl:attribute>
</img>
<div id="Div4" offy="100" class="ms-tileview-tile-detailsBox">
<ul class="ms-noList ms-tileview-tile-detailsListMedium">
<li id="Li3" collapsed="ms-tileview-tile-titleMedium ms-tileview-tile-titleMediumCollapsed" expanded="ms-tileview-tile-titleMedium ms-tileview-tile-titleMediumExpanded" class="ms-tileview-tile-titleMedium ms-tileview-tile-titleMediumCollapsed">
<div collapsed="ms-tileview-tile-titleTextMediumCollapsed" expanded="ms-tileview-tile-titleTextMediumExpanded" class="ms-tileview-tile-titleTextMediumCollapsed"&gt;&lt;xsl:value-of disable-output-escaping="yes" select="@Title" />
</div>
</li>
<li title="@Title" id="Li4" class="ms-tileview-tile-descriptionMedium"&gt;&lt;xsl:value-of disable-output-escaping="yes" select="@Description" ></li>
</ul>
</div>
</a>
</div>
</div>
</xsl:template>
view raw tiles.xsl hosted with ❤ by GitHub


4. Update your stylesheet with below
<style type="text/css">
.ms-tileview-tile-detailsBox {
width: 150px; height: 150px; top: 100px; left: 0px;
-webkit-transition: 300ms 0ms;
-webkit-transform-origin-x: -25px; }
.ms-tileview-tile-content:hover .ms-tileview-tile-detailsBox {
top:0px !important;
-webkit-transition: 300ms 0ms;
-webkit-transform-origin-x: -25px;
}
</style>
view raw cqwptiles.css hosted with ❤ by GitHub


5. Insert a CQWP, select your list, the above Item Style set your expiry filter and update the presentation fields.

You get the following: